-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested crates #1304
Nested crates #1304
Changes from all commits
f3ad479
1fba5bc
3c09995
1635ac3
2720d6c
f3e474f
bc97923
8242c67
596df84
8d187b5
7cf56f3
f9946ec
d137704
1d48fa5
5587e1c
06d9cbe
bf5cd72
9948c55
6fa0f83
add5459
b0ca91d
6a7ac10
9d74122
d380b51
f2fc75a
e7f6781
5f3daab
82c3d45
3bdecdb
774ba58
79ee638
aa4d06f
d0591a9
41d2e81
59af9a9
e8417d5
8996708
14c2cfc
311e22b
23c2c9d
de6cd1b
a73cbc0
47157bb
a26ff55
e2cf708
e4da311
cdb08fc
a5c5adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,4 +458,37 @@ METADATA | |
); | ||
</sql> | ||
</revision> | ||
<revision version="30" min_compatible="3"> | ||
<description> | ||
Add tables to support nested crates. | ||
</description> | ||
<sql> | ||
CREATE TABLE IF NOT EXISTS crateClosure ( | ||
parentId INTEGER, | ||
childId INTEGER, | ||
depth INTEGER | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS cratePath ( | ||
crateId INTEGER, | ||
idPath TEXT, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a comment like |
||
namePath TEXT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "This contains a / separated string of crate names" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way: how do you treat names which includes a "/"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it smart to store the namePath in the Database? This is a redundant information which can be wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storing redundant information for optimizing queries is not an issue as long as you are able to guarantee consistency, either immediately or at least eventually. The method of choice for immediate consistency is encapsulation with hooks that are triggered when needed and everything enclosed in a transaction scope. I remember that the my last review revealed that consistency cannot be guaranteed by the current implementation, because the transaction scoping was missing. Considering the fact that the whole hierarchy is abandoned and flattened when any inconsistencies are detected, this is a no-go for production and needs to be fixed. |
||
); | ||
|
||
ALTER TABLE crates RENAME TO old_crates; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apparently you can't alter a column's unique status, so I had to create the crates table again this time with the name not unique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a comment about removing the unique constraint from the name column. The SQL code does not reveal this fact. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ping! |
||
|
||
CREATE TABLE crates ( | ||
id integer PRIMARY KEY AUTOINCREMENT, | ||
name varchar(48) NOT NULL, | ||
count integer DEFAULT 0, | ||
show integer DEFAULT 1, | ||
locked integer DEFAULT 0, | ||
autodj_source integer DEFAULT 0 | ||
); | ||
|
||
INSERT INTO crates SELECT * FROM old_crates; | ||
|
||
DROP TABLE old_crates; | ||
</sql> | ||
</revision> | ||
</schema> |
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.
Explicitly specify a primary key id column for each table. Otherwise it will be created implicitly as ROWID. But omit the keyword AUTOINCREMENT:
https://sqlite.org/autoinc.html
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.
@uklotzde: Why is that an issue?
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.
Whith AUTOINCREMENT SQLite needs to keep track of the greatest ID value that has ever been used in a separate table. Without the keyword it can simply leverage the primary key index of the table itself and reuse any currently unused ID value:
https://www.sqlite.org/autoinc.html
Two use cases for AUTOCOMMIT: