-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration to delete everything image based
- Loading branch information
Dorien Grönwald
committed
Feb 28, 2025
1 parent
b0fde7e
commit ebd677e
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
internal/storage/postgres/migrations/20250228111747_delete_images.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
DROP TRIGGER IF EXISTS update_images_updated_at ON images; | ||
DROP TABLE IF EXISTS tree_images; | ||
DROP TABLE IF EXISTS images; | ||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
CREATE TABLE IF NOT EXISTS images ( | ||
id SERIAL PRIMARY KEY, | ||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
url TEXT NOT NULL, | ||
filename TEXT, | ||
mime_type TEXT | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS tree_images ( | ||
tree_id INT, | ||
image_id INT, | ||
PRIMARY KEY (tree_id, image_id), | ||
FOREIGN KEY (tree_id) REFERENCES trees(id), | ||
FOREIGN KEY (image_id) REFERENCES images(id) | ||
); | ||
|
||
CREATE TRIGGER update_images_updated_at | ||
BEFORE UPDATE ON images | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_updated_at_column(); | ||
-- +goose StatementEnd |