|
| 1 | +use crate::migrations::*; |
| 2 | + |
1 | 3 | use api::error::VssError; |
2 | 4 | use api::kv_store::{KvStore, GLOBAL_VERSION_KEY, INITIAL_RECORD_VERSION}; |
3 | 5 | use api::types::{ |
@@ -27,46 +29,6 @@ const KEY_COLUMN: &str = "key"; |
27 | 29 | const VALUE_COLUMN: &str = "value"; |
28 | 30 | const VERSION_COLUMN: &str = "version"; |
29 | 31 |
|
30 | | -const DB_VERSION_COLUMN: &str = "db_version"; |
31 | | -#[cfg(test)] |
32 | | -const MIGRATION_LOG_COLUMN: &str = "upgrade_from"; |
33 | | - |
34 | | -const CHECK_DB_STMT: &str = "SELECT 1 FROM pg_database WHERE datname = $1"; |
35 | | -const INIT_DB_CMD: &str = "CREATE DATABASE"; |
36 | | -#[cfg(test)] |
37 | | -const DROP_DB_CMD: &str = "DROP DATABASE"; |
38 | | -const GET_VERSION_STMT: &str = "SELECT db_version FROM vss_db_version;"; |
39 | | -const UPDATE_VERSION_STMT: &str = "UPDATE vss_db_version SET db_version=$1;"; |
40 | | -const LOG_MIGRATION_STMT: &str = "INSERT INTO vss_db_upgrades VALUES($1);"; |
41 | | -#[cfg(test)] |
42 | | -const GET_MIGRATION_LOG_STMT: &str = "SELECT upgrade_from FROM vss_db_upgrades;"; |
43 | | - |
44 | | -// APPEND-ONLY list of migration statements |
45 | | -// |
46 | | -// Each statement MUST be applied in-order, and only once per database. |
47 | | -// |
48 | | -// We make an exception for the vss_db table creation statement, as users of VSS could have initialized the table |
49 | | -// themselves. |
50 | | -const MIGRATIONS: &[&str] = &[ |
51 | | - "CREATE TABLE vss_db_version (db_version INTEGER);", |
52 | | - "INSERT INTO vss_db_version VALUES(1);", |
53 | | - // A write-only log of all the migrations performed on this database, useful for debugging and testing |
54 | | - "CREATE TABLE vss_db_upgrades (upgrade_from INTEGER);", |
55 | | - // We do not complain if the table already exists, as users of VSS could have already created this table |
56 | | - "CREATE TABLE IF NOT EXISTS vss_db ( |
57 | | - user_token character varying(120) NOT NULL CHECK (user_token <> ''), |
58 | | - store_id character varying(120) NOT NULL CHECK (store_id <> ''), |
59 | | - key character varying(600) NOT NULL, |
60 | | - value bytea NULL, |
61 | | - version bigint NOT NULL, |
62 | | - created_at TIMESTAMP WITH TIME ZONE, |
63 | | - last_updated_at TIMESTAMP WITH TIME ZONE, |
64 | | - PRIMARY KEY (user_token, store_id, key) |
65 | | - );", |
66 | | -]; |
67 | | -#[cfg(test)] |
68 | | -const DUMMY_MIGRATION: &str = "SELECT 1 WHERE FALSE;"; |
69 | | - |
70 | 32 | /// The maximum number of key versions that can be returned in a single page. |
71 | 33 | /// |
72 | 34 | /// This constant helps control memory and bandwidth usage for list operations, |
|
0 commit comments