-
Notifications
You must be signed in to change notification settings - Fork 18
Create and initialize the database if it does not exist #55
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
pub(crate) const DB_VERSION_COLUMN: &str = "db_version"; | ||
#[cfg(test)] | ||
pub(crate) const MIGRATION_LOG_COLUMN: &str = "upgrade_from"; | ||
|
||
pub(crate) const CHECK_DB_STMT: &str = "SELECT 1 FROM pg_database WHERE datname = $1"; | ||
pub(crate) const INIT_DB_CMD: &str = "CREATE DATABASE"; | ||
#[cfg(test)] | ||
const DROP_DB_CMD: &str = "DROP DATABASE"; | ||
pub(crate) const GET_VERSION_STMT: &str = "SELECT db_version FROM vss_db_version;"; | ||
pub(crate) const UPDATE_VERSION_STMT: &str = "UPDATE vss_db_version SET db_version=$1;"; | ||
pub(crate) const LOG_MIGRATION_STMT: &str = "INSERT INTO vss_db_upgrades VALUES($1);"; | ||
#[cfg(test)] | ||
pub(crate) const GET_MIGRATION_LOG_STMT: &str = "SELECT upgrade_from FROM vss_db_upgrades;"; | ||
|
||
// APPEND-ONLY list of migration statements | ||
// | ||
// Each statement MUST be applied in-order, and only once per database. | ||
// | ||
// We make an exception for the vss_db table creation statement, as users of VSS could have initialized the table | ||
// themselves. | ||
pub(crate) const MIGRATIONS: &[&str] = &[ | ||
"CREATE TABLE vss_db_version (db_version INTEGER);", | ||
"INSERT INTO vss_db_version VALUES(1);", | ||
// A write-only log of all the migrations performed on this database, useful for debugging and testing | ||
"CREATE TABLE vss_db_upgrades (upgrade_from INTEGER);", | ||
// We do not complain if the table already exists, as users of VSS could have already created this table | ||
"CREATE TABLE IF NOT EXISTS vss_db ( | ||
user_token character varying(120) NOT NULL CHECK (user_token <> ''), | ||
store_id character varying(120) NOT NULL CHECK (store_id <> ''), | ||
key character varying(600) NOT NULL, | ||
value bytea NULL, | ||
version bigint NOT NULL, | ||
created_at TIMESTAMP WITH TIME ZONE, | ||
last_updated_at TIMESTAMP WITH TIME ZONE, | ||
PRIMARY KEY (user_token, store_id, key) | ||
);", | ||
]; | ||
#[cfg(test)] | ||
const DUMMY_MIGRATION: &str = "SELECT 1 WHERE FALSE;"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.