Julio Biason
3 years ago
3 changed files with 47 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||||
|
-- Projects |
||||||
|
CREATE TABLE project ( |
||||||
|
id INTEGER NOT NULL PRIMARY KEY, |
||||||
|
name TEXT NOT NULL |
||||||
|
); |
||||||
|
CREATE UNIQUE INDEX project_name ON project (name); |
||||||
|
|
||||||
|
CREATE TABLE tag ( |
||||||
|
id INTEGER NOT NULL PRIMARY KEY, |
||||||
|
label TEXT NOT NULL |
||||||
|
) |
||||||
|
CREATE UNIQUE INDEX tag_label ON tag (label); |
||||||
|
|
||||||
|
CREATE TABLE entry ( |
||||||
|
id INTEGER NOT NULL PRIMARY KEY, |
||||||
|
start_ts DATETIME NOT NULL, |
||||||
|
stop_ts DATETIME, |
||||||
|
project_id INTEGER NOT NULL, |
||||||
|
FOREIGN KEY (project_id) REFERENCES project (id) |
||||||
|
); |
||||||
|
|
||||||
|
CREATE TABLE entry_tags ( |
||||||
|
id INTEGER NOT NULL PRIMARY KEY, |
||||||
|
entry_id INTEGER NOT NULL, |
||||||
|
tag_id INTEGER NOT NULL, |
||||||
|
CONSTRAINT UNIQUE (entry_id, tag_id), |
||||||
|
FOREIGN KEY (entry_id) REFERENCES entry (id), |
||||||
|
FOREIGN KEY (tag_id) REFERENCES tag (id) |
||||||
|
) |
@ -0,0 +1,16 @@ |
|||||||
|
use sqlx::sqlite::Sqlite; |
||||||
|
use sqlx::sqlite::SqliteConnectOptions; |
||||||
|
use sqlx::sqlite::SqlitePoolOptions; |
||||||
|
use sqlx::Pool; |
||||||
|
|
||||||
|
async fn connect() -> Result<Pool<Sqlite>, sqlx::Error> { |
||||||
|
let pool = SqlitePoolOptions::new() |
||||||
|
.connect_with( |
||||||
|
SqliteConnectOptions::new() |
||||||
|
.filename("testing.sqlite") |
||||||
|
.create_if_missing(true), |
||||||
|
) |
||||||
|
.await?; |
||||||
|
sqlx::migrate("migrations").run(&pool).await?; |
||||||
|
Ok(pool) |
||||||
|
} |
Loading…
Reference in new issue