Skip to content
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

Fix database migration and make them more consistent #955

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions daos/mysql/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ public function __construct() {
'INSERT INTO ' . \F3::get('db_prefix') . 'version (version) VALUES (11)'
]);
}
if (strnatcmp($version, '12') < 0) {
\F3::get('db')->exec([
'UPDATE ' . \F3::get('db_prefix') . 'items SET updatetime = datetime WHERE updatetime IS NULL',
'ALTER TABLE ' . \F3::get('db_prefix') . 'items MODIFY updatetime DATETIME NOT NULL',
'ALTER TABLE ' . \F3::get('db_prefix') . 'items MODIFY lastseen DATETIME NOT NULL',
'INSERT INTO ' . \F3::get('db_prefix') . 'version (version) VALUES (12)'
]);
}
}

// just initialize once
Expand Down
7 changes: 7 additions & 0 deletions daos/pgsql/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ public function __construct() {
'INSERT INTO version (version) VALUES (11);'
]);
}
if (strnatcmp($version, '12') < 0) {
\F3::get('db')->exec([
'UPDATE items SET updatetime = datetime WHERE updatetime IS NULL',
'ALTER TABLE items ALTER COLUMN updatetime SET NOT NULL',
'INSERT INTO version (version) VALUES (12)'
]);
}
}

// just initialize once
Expand Down
1 change: 1 addition & 0 deletions daos/sqlite/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function __construct() {
shared BOOL,
lastseen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)',
'UPDATE items SET updatetime = datetime WHERE updatetime IS NULL',
'INSERT INTO new_items SELECT *, CURRENT_TIMESTAMP FROM items',
'DROP TABLE items',
'ALTER TABLE new_items RENAME TO items',
Expand Down