diff options
author | Teddy Wing | 2021-05-30 17:48:15 +0200 |
---|---|---|
committer | Teddy Wing | 2021-05-30 17:48:15 +0200 |
commit | 966a93e0f72cb0129b2bfeb5eb4a8f3b462de5b6 (patch) | |
tree | 49f7b6d910be610639a475741735cd4b6d85fa9d | |
parent | c6a4ecfde6034853ed2f8d13571170da69797835 (diff) | |
download | reflectub-966a93e0f72cb0129b2bfeb5eb4a8f3b462de5b6.tar.bz2 |
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.
-rw-r--r-- | src/database.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 2 |
2 files changed, 3 insertions, 3 deletions
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 |