added database crate, "settings" with migrations and queries, running migrations on web startup
This commit is contained in:
parent
f60eb616d3
commit
9c2b43ec3c
16 changed files with 357 additions and 1 deletions
48
crates/database/justfile
Executable file
48
crates/database/justfile
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env just --justfile
|
||||
|
||||
database_dir := justfile_directory() + "/../../database"
|
||||
database_file := "ezidam.sqlite"
|
||||
database_path := database_dir / database_file
|
||||
|
||||
database_url := "sqlite://" + absolute_path(database_path)
|
||||
sqlx_database := "--database-url " + database_url
|
||||
|
||||
cargo := "cargo"
|
||||
|
||||
# list recipes
|
||||
default:
|
||||
just --list
|
||||
|
||||
# prepare sql queries for offline usage
|
||||
offline:
|
||||
{{cargo}} sqlx prepare {{sqlx_database}}
|
||||
|
||||
# verify offline data is up to date
|
||||
offline_check:
|
||||
{{cargo}} sqlx prepare --check {{sqlx_database}}
|
||||
|
||||
# run pending migrations
|
||||
run:
|
||||
sqlx migrate run {{sqlx_database}}
|
||||
|
||||
# add new migration
|
||||
new name:
|
||||
sqlx migrate add -r {{name}}
|
||||
|
||||
# revert latest migration
|
||||
revert_last:
|
||||
sqlx migrate revert {{sqlx_database}}
|
||||
|
||||
# create database
|
||||
create:
|
||||
mkdir -p {{database_dir}}
|
||||
sqlx database create {{sqlx_database}}
|
||||
|
||||
# reset database and apply migrations
|
||||
reset:
|
||||
mkdir -p {{database_dir}}
|
||||
sqlx database reset {{sqlx_database}}
|
||||
|
||||
# create a build script to trigger recompilation when a new migration is added
|
||||
build_script:
|
||||
sqlx migrate build-script
|
||||
Loading…
Add table
Add a link
Reference in a new issue