-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This file has currently been populated with sql auto-generated from the peewee models code. Please note that no changes have been made to the auto-generated code yet, except for expanding it into many lines for better readability. Further optimization will be following soon in a series of commits, including changing the structure to match the one discussed in the meeting of 2015-08-07....
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
CREATE TABLE "group" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"position" INTEGER NOT NULL, "name" VARCHAR(128) NOT NULL, | ||
"visible" SMALLINT NOT NULL | ||
); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
CREATE INDEX "group_name" ON "group" ("name"); | ||
|
||
|
||
CREATE TABLE "user" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"username" VARCHAR(32) NOT NULL, | ||
"password" VARCHAR(512), | ||
"group_id" INTEGER NOT NULL, | ||
"refnum" VARCHAR(255), | ||
"name" VARCHAR(64) NOT NULL, | ||
"email" VARCHAR(64), | ||
"phone" VARCHAR(16), | ||
"birthday" DATE, | ||
"active" SMALLINT NOT NULL, | ||
FOREIGN KEY ("group_id") REFERENCES "group" ("id") | ||
); | ||
CREATE UNIQUE INDEX "user_username" ON "user" ("username"); | ||
CREATE INDEX "user_group_id" ON "user" ("group_id"); | ||
|
||
CREATE TABLE "publishplace" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(512) NOT NULL | ||
This comment has been minimized.
Sorry, something went wrong.
badrihippo
Author
Owner
|
||
); | ||
CREATE UNIQUE INDEX "publishplace_name" ON "publishplace" ("name"); | ||
|
||
CREATE TABLE "publisher" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(256) NOT NULL, | ||
"address" TEXT, | ||
"imprint_of_id" INTEGER, | ||
FOREIGN KEY ("imprint_of_id") REFERENCES "publisher" ("id") | ||
); | ||
This comment has been minimized.
Sorry, something went wrong.
badrihippo
Author
Owner
|
||
CREATE INDEX "publisher_imprint_of_id" ON "publisher" ("imprint_of_id"); | ||
|
||
CREATE TABLE "currency" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(32) NOT NULL, | ||
"symbol" VARCHAR(4) NOT NULL, | ||
"conversion_factor" REAL NOT NULL | ||
This comment has been minimized.
Sorry, something went wrong.
badrihippo
Author
Owner
|
||
); | ||
CREATE UNIQUE INDEX "currency_name" ON "currency" ("name"); | ||
|
||
|
||
CREATE TABLE "author" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(128) NOT NULL, | ||
"is_pseudonym" SMALLINT NOT NULL, | ||
"author_sort" VARCHAR(128) NOT NULL | ||
); | ||
This comment has been minimized.
Sorry, something went wrong.
badrihippo
Author
Owner
|
||
CREATE INDEX "author_author_sort" ON "author" ("author_sort"); | ||
|
||
|
||
CREATE TABLE "location" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"name" VARCHAR(256) NOT NULL, | ||
"prevent_borrowing" SMALLINT NOT NULL | ||
); | ||
CREATE UNIQUE INDEX "location_name" ON "location" ("name"); | ||
|
||
CREATE TABLE "publication" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"title" VARCHAR(512) NOT NULL, | ||
"display_title" VARCHAR(256) NOT NULL, | ||
"pubtype" VARCHAR(255), | ||
"pubdata_id" INTEGER, | ||
"identifier" VARCHAR(256), | ||
"call_no" VARCHAR(8) NOT NULL, | ||
"keywords" VARCHAR(1024), | ||
"comments" TEXT | ||
); | ||
|
||
CREATE TABLE "copy" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"accession" INTEGER NOT NULL, | ||
"item_id" INTEGER NOT NULL, | ||
"location_id" INTEGER NOT NULL, | ||
"copydata_type" VARCHAR(255), | ||
"copydata_id" VARCHAR(255), | ||
"price" REAL, | ||
"price_currency_id" INTEGER, | ||
"receipt_date" DATE, | ||
"source" VARCHAR(512), | ||
FOREIGN KEY ("item_id") REFERENCES "publication" ("id"), | ||
FOREIGN KEY ("location_id") REFERENCES "location" ("id"), | ||
FOREIGN KEY ("price_currency_id") REFERENCES "currency" ("id") | ||
); | ||
CREATE INDEX "copy_price_currency_id" ON "copy" ("price_currency_id"); | ||
CREATE UNIQUE INDEX "copy_accession" ON "copy" ("accession"); | ||
CREATE INDEX "copy_item_id" ON "copy" ("item_id"); | ||
CREATE INDEX "copy_location_id" ON "copy" ("location_id"); | ||
|
||
|
||
CREATE TABLE "borrowing" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"copy_id" INTEGER NOT NULL, | ||
"user_id" INTEGER NOT NULL, | ||
"group_id" INTEGER NOT NULL, | ||
"borrow_date" DATETIME NOT NULL, | ||
"renew_times" INTEGER NOT NULL, | ||
"is_longterm" SMALLINT NOT NULL, | ||
FOREIGN KEY ("copy_id") REFERENCES "copy" ("id"), | ||
FOREIGN KEY ("user_id") REFERENCES "user" ("id"), | ||
FOREIGN KEY ("group_id") REFERENCES "group" ("id")); | ||
CREATE INDEX "borrowing_group_id" ON "borrowing" ("group_id"); | ||
CREATE INDEX "borrowing_user_id" ON "borrowing" ("user_id"); | ||
CREATE UNIQUE INDEX "borrowing_copy_id" ON "borrowing" ("copy_id"); | ||
|
||
|
||
CREATE TABLE "pastborrowing" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"accession" INTEGER NOT NULL, "user_id" INTEGER NOT NULL, | ||
"group_id" INTEGER NOT NULL, "borrow_date" DATETIME NOT NULL, | ||
"return_date" DATETIME NOT NULL, | ||
FOREIGN KEY ("user_id") REFERENCES "user" ("id"), | ||
FOREIGN KEY ("group_id") REFERENCES "group" ("id") | ||
); | ||
CREATE INDEX "pastborrowing_group_id" ON "pastborrowing" ("group_id"); | ||
CREATE INDEX "pastborrowing_user_id" ON "pastborrowing" ("user_id"); | ||
|
||
|
||
CREATE TABLE "copybook" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"pub_name_id" INTEGER, "pub_place_id" INTEGER, | ||
"pub_date" DATE, | ||
FOREIGN KEY ("pub_name_id") REFERENCES "publisher" ("id"), | ||
FOREIGN KEY ("pub_place_id") REFERENCES "publishplace" ("id") | ||
); | ||
CREATE INDEX "copybook_pub_place_id" ON "copybook" ("pub_place_id"); | ||
CREATE INDEX "copybook_pub_name_id" ON "copybook" ("pub_name_id"); | ||
|
||
|
||
CREATE TABLE "pubperiodical" | ||
( | ||
"id" INTEGER NOT NULL PRIMARY KEY, | ||
"cover_content" VARCHAR(512), | ||
"issue" INTEGER, | ||
"vol_no" INTEGER, | ||
"vol_issue" INTEGER, | ||
"date" DATE, | ||
"date_hide_day" SMALLINT | ||
); |
9 comments
on commit da807d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE TABLE "group"
+(
- "id" INTEGER NOT NULL PRIMARY KEY,
- "position" INTEGER NOT NULL, "name" VARCHAR(128) NOT NULL,
- "visible" SMALLINT NOT NULL
+);
Here, can we have name as UserGroup for easy understanding. This will be a table with very rows. So why have an integer field as PK ? Can we not have groupname itself as PK ? This will avoid lookups to bring up the name. I am not clear on the fields position and visible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE TABLE "publishplace"
+(
- "id" INTEGER NOT NULL PRIMARY KEY,
- "name" VARCHAR(512) NOT NULL
+);
Here also we can remove the field id. Change the "name" field to call it place or something more relevant and make that as the PK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE TABLE "publisher"
+(
- "id" INTEGER NOT NULL PRIMARY KEY,
- "name" VARCHAR(256) NOT NULL,
- "address" TEXT,
- "imprint_of_id" INTEGER,
- Name need not be 256. Maybe 128 ?
- Why e the field names as id and name in every table ? Can we not have more meaningful names as relevant for that table ?
- Why address is text ? Why not varchar ?
- What is imprint of id ? I am not clear. Further, it ends up being circular reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE TABLE "currency"
+(
- "id" INTEGER NOT NULL PRIMARY KEY,
- "name" VARCHAR(32) NOT NULL,
- "symbol" VARCHAR(4) NOT NULL,
- "conversion_factor" REAL NOT NULL
+); - No need for id. Make the name , curr_name as PK
- Conversion factor has no significance without a date. We discussed the other day and decided not to have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CREATE TABLE "author"
+(
- "id" INTEGER NOT NULL PRIMARY KEY,
- "name" VARCHAR(128) NOT NULL,
- "is_pseudonym" SMALLINT NOT NULL,
- "author_sort" VARCHAR(128) NOT NULL
+);
+CREATE INDEX "author_author_sort" ON "author" ("author_sort");
- We didnt discuss on the need for author master. Is it required ? Considering same author names may appear differently in different books, is it required to master this ? We need to know from Yasho. Also, is it there in Merlin now ?
- Even if required, what is the need for the is_pseudonym and author-sort fields ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Location table also doesnt need id and name separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didnt list down publication as a master table. Would like to know more about the need for this table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see tables for user role, genre and item type. Please create them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KrishnaRamamoorthy: I've put more replies inline. The publication
table was from the auto-generated code; I had already removed in the next commit (f0b1cbb). User Role is being implemented using a framework (Flask-Principal), so I'll have to learn how that works before including it into the table. I'll add genre and item type: thanks for pointing those out.
OK, I'll change the name to user_group (btw you can also do edits directly by clicking on the pencil button)
The reason for a separate
name
andid
was that I thought renames would be easier if they were separate (plus @aparnaswamy was saying we should avoid non-integer pk's as much as possible). If you think renaming won't be such a problem (not a common operation or something) then I can merge the fields (or mergeid
withposition
; see below).position
is for determining the order in which the UserGroup appears on places like the login page (Sarala, Bilva, Tamala, Ashwatha; not Ashwatha, Bilva, Sarala, Tamala). Maybe the name can be changed toordering
or something if that'll make it more clear.visible
is to decide whether that UserGroup is visible in places like the login page or not. In case we want to hide the group but keep it internally for past records. I've actually created an "issue" on the question of storing past records; you can see (and discuss!) at: #3.