mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Schema migrations for stand alone recipe plans
This commit is contained in:
parent
1d924fb702
commit
08e7f41be1
3
Makefile
3
Makefile
@ -44,6 +44,9 @@ clean:
|
||||
sqlx-migrate:
|
||||
cd kitchen; cargo sqlx migrate run --database-url $(sqlite_url)
|
||||
|
||||
sqlx-add-%:
|
||||
cd kitchen; cargo sqlx migrate add -r $*
|
||||
|
||||
sqlx-revert:
|
||||
cd kitchen; cargo sqlx migrate revert --database-url $(sqlite_url)
|
||||
|
||||
|
2
kitchen/migrations/20230321193852_plan-table.down.sql
Normal file
2
kitchen/migrations/20230321193852_plan-table.down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- Add down migration script here
|
||||
drop table plan_table;
|
10
kitchen/migrations/20230321193852_plan-table.up.sql
Normal file
10
kitchen/migrations/20230321193852_plan-table.up.sql
Normal file
@ -0,0 +1,10 @@
|
||||
-- Add up migration script here
|
||||
create temp table TEMP_plan_dates_deduped AS
|
||||
select distinct user_id, plan_date from plan_recipes;
|
||||
|
||||
create table plan_table (user_id TEXT NOT NULL, plan_date TEXT NOT NULL, primary key (user_id, plan_date) );
|
||||
|
||||
insert into plan_table
|
||||
select user_id, plan_date from TEMP_plan_dates_deduped;
|
||||
|
||||
drop table TEMP_plan_dates_deduped;
|
@ -470,24 +470,6 @@
|
||||
},
|
||||
"query": "select\n filtered_ingredients.name,\n filtered_ingredients.form,\n filtered_ingredients.measure_type\nfrom filtered_ingredients\nwhere\n user_id = ?\n and plan_date = ?"
|
||||
},
|
||||
"7f4abc448b16e8b6b2bb74f8e810e245e81b38e1407085a20d28bfddfc06891f": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "plan_date: NaiveDate",
|
||||
"ordinal": 0,
|
||||
"type_info": "Date"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "select distinct plan_date as \"plan_date: NaiveDate\" from plan_recipes\nwhere user_id = ?"
|
||||
},
|
||||
"83824ea638cb64c524f5c8984ef6ef28dfe781f0abf168abc4ae9a51e6e0ae88": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
@ -643,5 +625,23 @@
|
||||
}
|
||||
},
|
||||
"query": "with latest_dates as (\n select user_id, max(date(plan_date)) as plan_date from plan_recipes\n where user_id = ?\n group by user_id\n)\n\nselect\n filtered_ingredients.name,\n filtered_ingredients.form,\n filtered_ingredients.measure_type\nfrom latest_dates\ninner join filtered_ingredients on\n latest_dates.user_id = filtered_ingredients.user_id\n and latest_dates.plan_date = filtered_ingredients.plan_date"
|
||||
},
|
||||
"fd818a6b1c800c2014b5cfe8a923ac9228832b11d7575585cf7930fbf91306d1": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "plan_date: NaiveDate",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
}
|
||||
},
|
||||
"query": "select distinct plan_date as \"plan_date: NaiveDate\" from plan_table\nwhere user_id = ?"
|
||||
}
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
select distinct plan_date as "plan_date: NaiveDate" from plan_recipes
|
||||
select distinct plan_date as "plan_date: NaiveDate" from plan_table
|
||||
where user_id = ?
|
2
kitchen/src/web/storage/init_meal_plan.sql
Normal file
2
kitchen/src/web/storage/init_meal_plan.sql
Normal file
@ -0,0 +1,2 @@
|
||||
insert into plan_table (user_id, plan_date) values (?, ?)
|
||||
on conflict (user_id, plan_date) do nothing;
|
Loading…
x
Reference in New Issue
Block a user