mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 18:58:18 +00:00
sqlite: create if not exists and run migrations
This commit is contained in:
16
migrations/20231006125208_init.sql
Normal file
16
migrations/20231006125208_init.sql
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE calendars (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
owner TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
color TEXT,
|
||||||
|
timezone TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE events (
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
cid TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (cid, uid),
|
||||||
|
FOREIGN KEY (cid) REFERENCES calendars(uid)
|
||||||
|
);
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ use rustical_caldav::{configure_dav, configure_well_known};
|
|||||||
use rustical_store::calendar::CalendarStore;
|
use rustical_store::calendar::CalendarStore;
|
||||||
use rustical_store::sqlite_store::SqliteCalendarStore;
|
use rustical_store::sqlite_store::SqliteCalendarStore;
|
||||||
use rustical_store::toml_store::TomlCalendarStore;
|
use rustical_store::toml_store::TomlCalendarStore;
|
||||||
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -39,7 +40,13 @@ async fn main() -> Result<()> {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
CalendarStoreConfig::Sqlite(SqliteCalendarStoreConfig { db_url }) => {
|
CalendarStoreConfig::Sqlite(SqliteCalendarStoreConfig { db_url }) => {
|
||||||
let db = SqlitePool::connect(db_url).await?;
|
let db = SqlitePool::connect_with(
|
||||||
|
SqliteConnectOptions::new()
|
||||||
|
.filename(db_url)
|
||||||
|
.create_if_missing(true),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
sqlx::migrate!("./migrations").run(&db).await?;
|
||||||
Arc::new(RwLock::new(SqliteCalendarStore::new(Arc::new(db))))
|
Arc::new(RwLock::new(SqliteCalendarStore::new(Arc::new(db))))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user