aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-04-23 16:27:00 +0200
committerJoris2022-04-23 16:27:00 +0200
commit6d271b09303d924381cc65e7c0b5eb56833780ed (patch)
tree7f6f2899efacab3e444ff80a32ea26da094d5f54
parent65fd0cb7c8b996cb43b6766feebe8fe84f836919 (diff)
Create categories table
-rw-r--r--src/db/migrations/2-categories.sql13
-rw-r--r--src/db/mod.rs5
2 files changed, 17 insertions, 1 deletions
diff --git a/src/db/migrations/2-categories.sql b/src/db/migrations/2-categories.sql
new file mode 100644
index 0000000..27e9699
--- /dev/null
+++ b/src/db/migrations/2-categories.sql
@@ -0,0 +1,13 @@
+CREATE TABLE IF NOT EXISTS "categories" (
+ "id" TEXT PRIMARY KEY, /* UUID */
+ "name" TEXT NOT NULL,
+ "color" TEXT NOT NULL, /* HEXA */
+ "created" TEXT NOT NULL, /* DATETIME */
+ "updated" TEXT NOT NULL /* DATETIME */
+);
+
+INSERT INTO
+ "categories" ("id", "name", "color", "created", "updated")
+ VALUES ("b2253284-1572-43d5-96ec-bf6ad448f46a", "Perso", "#a8c2e0", datetime(), datetime());
+
+ALTER TABLE "events" ADD COLUMN "category" TEXT REFERENCES "categories" ("id"); /* UUID */
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 3d498a8..101c874 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -8,7 +8,10 @@ use crate::model::event::Event;
pub fn init(db_path: &str) -> Result<Connection> {
let mut conn = Connection::open(db_path)?;
- let migrations = Migrations::new(vec![M::up(include_str!("migrations/1-init.sql"))]);
+ let migrations = Migrations::new(vec![
+ M::up(include_str!("migrations/1-init.sql")),
+ M::up(include_str!("migrations/2-categories.sql")),
+ ]);
migrations.to_latest(&mut conn)?;
Ok(conn)
}