From 966a93e0f72cb0129b2bfeb5eb4a8f3b462de5b6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 May 2021 17:48:15 +0200 Subject: database: Always try to create the database and tables This is simpler, and means we don't have to check if the database file exists and only initialise if it doesn't. Here, we can just run the code and trust it will do the right thing in both cases. --- src/database.rs | 4 ++-- src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/database.rs b/src/database.rs index 9fa38fc..22314ee 100644 --- a/src/database.rs +++ b/src/database.rs @@ -53,7 +53,7 @@ impl Db { let mut tx = self.connection.begin().await?; tx.execute(r#" - CREATE TABLE repositories ( + CREATE TABLE IF NOT EXISTS repositories ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, description TEXT, @@ -62,7 +62,7 @@ impl Db { "#).await?; tx.execute(r#" - CREATE UNIQUE INDEX idx_repositories_id + CREATE UNIQUE INDEX IF NOT EXISTS idx_repositories_id ON repositories (id); "#).await?; diff --git a/src/main.rs b/src/main.rs index c864ee6..2a3e988 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ async fn main() { let mut db = database::Db::connect("test.db").await.unwrap(); - // db.create().await.unwrap(); + db.create().await.unwrap(); // If repo !exists // insert -- cgit v1.2.3