@@ -6,7 +6,6 @@ use version::version;
7#[derive(Serialize, Deserialize, Debug)]
7#[derive(Serialize, Deserialize, Debug)]
8pub struct State {
8pub struct State {
10 pub status: Status,
9 pub status: Status,
@@ -139,9 +138,12 @@ impl State {
139 fn ensure_schema_and_table(db: &mut impl Conn) {
138 fn ensure_schema_and_table(db: &mut impl Conn) {
140 db.run("CREATE SCHEMA IF NOT EXISTS reshape").unwrap();
139 db.run("CREATE SCHEMA IF NOT EXISTS reshape").unwrap();
141+ // Create data table which will be a key-value table containing
142+ // the version and current state.
142 db.run("CREATE TABLE IF NOT EXISTS reshape.data (key TEXT PRIMARY KEY, value JSONB)")
143 db.run("CREATE TABLE IF NOT EXISTS reshape.data (key TEXT PRIMARY KEY, value JSONB)")
143 .unwrap();
144 .unwrap();
146+ // Create migrations table which will store all completed migrations
147 CREATE TABLE IF NOT EXISTS reshape.migrations (
149 CREATE TABLE IF NOT EXISTS reshape.migrations (
@@ -154,13 +156,24 @@ impl State {
156 .unwrap();
158 .unwrap();
160+ // Update the current version
161+ let encoded_version = serde_json::to_value(version!().to_string()).unwrap();
162+ db.query_with_params(
164+ INSERT INTO reshape.data (key, value)
165+ VALUES ('version', $1)
166+ ON CONFLICT (key) DO UPDATE SET value = $1
168+ &[&encoded_version],
160impl Default for State {
174impl Default for State {
161 fn default() -> Self {
175 fn default() -> Self {
163− version: version!().to_string(),
164 status: Status::Idle,
177 status: Status::Idle,