Skip to content

Commit

Permalink
Fix migration files
Browse files Browse the repository at this point in the history
  • Loading branch information
szabolcs-horvath committed Dec 19, 2024
1 parent a3e1b70 commit 15e9733
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,34 @@ migrate-up:
migrate-up-1:
migrate -source file://$(SQLITE_MIGRATIONS_DIR) -database sqlite3://$(SQLITE_DB_FILE) up 1

migrate-up-file:
ifneq ($(SPECIFIED_DB_FILE),)
migrate -source file://$(SQLITE_MIGRATIONS_DIR) -database sqlite3://$(SPECIFIED_DB_FILE) up
else
@echo "SPECIFIED_DB_FILE needs to be specified. Usage: make migrate-up-file SPECIFIED_DB_FILE=<db_file>"
exit 1
endif

migrate-up-1-file:
ifneq ($(SPECIFIED_DB_FILE),)
migrate -source file://$(SQLITE_MIGRATIONS_DIR) -database sqlite3://$(SPECIFIED_DB_FILE) up 1
else
@echo "SPECIFIED_DB_FILE needs to be specified. Usage: make migrate-up-1-file SPECIFIED_DB_FILE=<db_file>"
exit 1
endif

migrate-down-1:
migrate -source file://$(SQLITE_MIGRATIONS_DIR) -database sqlite3://$(SQLITE_DB_FILE) down 1

migrate-down-1-file:
ifneq ($(SPECIFIED_DB_FILE),)
migrate -source file://$(SQLITE_MIGRATIONS_DIR) -database sqlite3://$(SPECIFIED_DB_FILE) down 1
else
@echo "SPECIFIED_DB_FILE needs to be specified. Usage: make migrate-down-1-file SPECIFIED_DB_FILE=<db_file>"
exit 1
endif


download-htmx:
cd ./web/static/vendor/htmx; \
curl -O https://unpkg.com/htmx.org@$(HTMX_VERSION)/dist/htmx.min.js; \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ALTER TABLE nutritions
DROP COLUMN carbs_slow_release_per_100g;
DROP COLUMN carbs_fast_release_per_100g;

ALTER TABLE nutritions
DROP COLUMN carbs_fast_release_per_100g;
DROP COLUMN carbs_slow_release_per_100g;
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SET calories_per_100g = (SELECT calories_per_100g FROM nutritions WHERE items.nu
WHERE EXISTS (SELECT 1 FROM nutritions WHERE items.nutrition_id = nutritions.id);


DROP TABLE IF EXISTS nutritions;

ALTER TABLE items DROP COLUMN nutrition_id;
ALTER TABLE items DROP COLUMN original_nutrition_id;
ALTER TABLE items DROP COLUMN nutrition_id;

DROP TABLE IF EXISTS nutritions;

Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
ALTER TABLE portions DROP COLUMN liquid;
CREATE TABLE IF NOT EXISTS portions_backup
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
owner_id INTEGER REFERENCES users,
language_id INTEGER REFERENCES languages,
weigth_in_grams REAL,
volume_in_ml REAL,
CHECK (volume_in_ml >= 0),
CHECK (weigth_in_grams >= 0),
CHECK (weigth_in_grams IS NOT NULL OR volume_in_ml IS NOT NULL)
);

INSERT INTO portions_backup
SELECT id, name, owner_id, language_id, weigth_in_grams, volume_in_ml FROM portions;

DROP TABLE IF EXISTS portions;

ALTER TABLE portions_backup RENAME TO portions;

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS portions_backup (
);

INSERT INTO portions_backup
SELECT * FROM portions;
SELECT id, name, owner_id, language_id, liquid, weigth_in_grams, volume_in_ml FROM portions;

DROP TABLE IF EXISTS portions;

Expand Down

0 comments on commit 15e9733

Please sign in to comment.