refactor: demo.db migration structure
Some checks failed
/ integration-test--firefox (push) Failing after 3m7s
Some checks failed
/ integration-test--firefox (push) Failing after 3m7s
This commit is contained in:
parent
1f05189ec6
commit
cd4096b2ff
9 changed files with 26 additions and 46 deletions
|
|
@ -1,12 +0,0 @@
|
||||||
create table if not exists contacts (
|
|
||||||
id integer primary key autoincrement,
|
|
||||||
birthday text,
|
|
||||||
manually_freshened_at date -- text, iso8601 date
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists names (
|
|
||||||
id integer primary key,
|
|
||||||
contact_id integer not null references contacts(id) on delete cascade,
|
|
||||||
sort integer not null,
|
|
||||||
name text not null
|
|
||||||
);
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
create table if not exists journal_entries (
|
|
||||||
id integer primary key autoincrement,
|
|
||||||
value text not null,
|
|
||||||
date text not null
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists contact_mentions (
|
|
||||||
entry_id integer not null references journal_entries(id) on delete cascade,
|
|
||||||
contact_id integer not null references contacts(id) on delete cascade,
|
|
||||||
input_text text not null,
|
|
||||||
byte_range_start integer not null,
|
|
||||||
byte_range_end integer not null
|
|
||||||
);
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
create table if not exists settings (
|
|
||||||
id integer primary key,
|
|
||||||
ics_path text
|
|
||||||
);
|
|
||||||
|
|
||||||
insert into settings (id) values (1) on conflict (id) do nothing;
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
create table if not exists addresses (
|
|
||||||
id integer primary key,
|
|
||||||
contact_id integer not null references contacts(id) on delete cascade,
|
|
||||||
label text,
|
|
||||||
value text not null
|
|
||||||
);
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
alter table contacts
|
|
||||||
add column
|
|
||||||
text_body text;
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
create table if not exists groups (
|
create table if not exists groups (
|
||||||
contact_id number not null references contacts(id),
|
contact_id integer not null references contacts(id) on delete cascade,
|
||||||
name text not null
|
name text not null
|
||||||
);
|
);
|
||||||
|
|
|
||||||
12
src/db.rs
12
src/db.rs
|
|
@ -23,12 +23,14 @@ impl Database {
|
||||||
|
|
||||||
let pool = SqlitePoolOptions::new().connect_with(db_options).await?;
|
let pool = SqlitePoolOptions::new().connect_with(db_options).await?;
|
||||||
|
|
||||||
let migrator = if user.username == "demo" {
|
sqlx::migrate!("./migrations/each_user/")
|
||||||
sqlx::migrate!("./migrations/demo.db/")
|
.run(&pool)
|
||||||
} else {
|
.await?;
|
||||||
sqlx::migrate!("./migrations/each_user/")
|
if user.username == "demo" {
|
||||||
|
sqlx::query_file!("./migrations/demo.sql")
|
||||||
|
.execute(&pool)
|
||||||
|
.await?;
|
||||||
};
|
};
|
||||||
migrator.run(&pool).await?;
|
|
||||||
|
|
||||||
Ok(Self { pool })
|
Ok(Self { pool })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,6 +227,16 @@ mod get {
|
||||||
.clone()
|
.clone()
|
||||||
.map_or("".to_string(), |m| m.to_rfc3339());
|
.map_or("".to_string(), |m| m.to_rfc3339());
|
||||||
|
|
||||||
|
let groups: Vec<String> = sqlx::query_as!(
|
||||||
|
Group,
|
||||||
|
"select * from groups where contact_id = $1",
|
||||||
|
contact_id)
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|group| group.name)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let text_body: String =
|
let text_body: String =
|
||||||
sqlx::query!("select text_body from contacts where id = $1", contact_id)
|
sqlx::query!("select text_body from contacts where id = $1", contact_id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
|
|
@ -287,6 +297,14 @@ mod get {
|
||||||
}
|
}
|
||||||
input type="button" value="Add" x-on:click="addresses.push({ label: new_label, value: new_address }); new_label = ''; new_address = ''";
|
input type="button" value="Add" x-on:click="addresses.push({ label: new_label, value: new_address }); new_label = ''; new_address = ''";
|
||||||
}
|
}
|
||||||
|
label { "groups" }
|
||||||
|
#groups x-data=(json!({ "groups": groups, "new_group": "" })) {
|
||||||
|
template x-for="(group, index) in groups" x-bind:key="index" {
|
||||||
|
input name="group" x-model="group" placeholder="group name";
|
||||||
|
}
|
||||||
|
input name="group" x-model="new_group" placeholder="group name";
|
||||||
|
input type="button" value="Add" x-on:click="groups.push(new_group); new_group = ''";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
div #text_body {
|
div #text_body {
|
||||||
div { "Free text (supports markdown)" }
|
div { "Free text (supports markdown)" }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue