Skip to content

Commit

Permalink
Add Meta table to core/ schema - store schema_version (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
panarch committed Dec 2, 2024
1 parent 879cd25 commit 5cdbac4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ use {
};

pub async fn setup(storage: &mut Storage) -> Result<DirectoryId> {
table("Meta")
.create_table_if_not_exists()
.add_column("key TEXT PRIMARY KEY")
.add_column("value TEXT NOT NULL")
.add_column("updated_at TIMESTAMP NOT NULL DEFAULT NOW()")
.execute(storage)
.await?;

table("Directory")
.create_table_if_not_exists()
.add_column("id UUID PRIMARY KEY DEFAULT GENERATE_UUID()")
Expand All @@ -30,6 +38,26 @@ pub async fn setup(storage: &mut Storage) -> Result<DirectoryId> {
.execute(storage)
.await?;

let schema_version_not_exists = table("Meta")
.select()
.filter(col("key").eq(text("schema_version")))
.project("key")
.execute(storage)
.await?
.select()
.unwrap()
.count()
== 0;

if schema_version_not_exists {
table("Meta")
.insert()
.columns(vec!["key", "value"])
.values(vec![vec![text("schema_version"), text("1")]])
.execute(storage)
.await?;
}

let root_not_exists = table("Directory")
.select()
.filter(col("parent_id").is_null())
Expand Down

0 comments on commit 5cdbac4

Please sign in to comment.