refactor: demo.db migration structure
Some checks failed
/ integration-test--firefox (push) Failing after 3m7s

This commit is contained in:
Robert Perce 2026-01-19 21:38:23 -06:00
parent 1f05189ec6
commit cd4096b2ff
9 changed files with 26 additions and 46 deletions

View file

@ -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
);

View file

@ -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
);

View file

@ -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;

View file

@ -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
);

View file

@ -1,3 +0,0 @@
alter table contacts
add column
text_body text;

View file

@ -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
); );

View file

@ -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/demo.db/")
} else {
sqlx::migrate!("./migrations/each_user/") sqlx::migrate!("./migrations/each_user/")
.run(&pool)
.await?;
if user.username == "demo" {
sqlx::query_file!("./migrations/demo.sql")
.execute(&pool)
.await?;
}; };
migrator.run(&pool).await?;
Ok(Self { pool }) Ok(Self { pool })
} }

View file

@ -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)" }