Skip to content

Commit

Permalink
feat: add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mikinovation committed Nov 11, 2024
1 parent c52cd2c commit fa7b25f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sandbox/rusty-book-manager/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sandbox/rusty-book-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ tokio = { version = "1.37.0", features = ["full"] }
rstest = "0.18.2"
async-trait = "0.1.74"
derive-new = "0.6.0"
uuid = { version = "1.4.0", features = ["v4", "serde"] }
serde = { version = "1.0.174", features = ["derive"] }
thiserror = "1.0.44"

[dependencies]
adapter.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions sandbox/rusty-book-manager/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ JAEGER_PORT = 6831
run_task = [
{ name = [
"compose-up-db",
"migrate",
"compose-up-redis",
]},
]
Expand Down Expand Up @@ -166,3 +167,8 @@ args = ["compose", "up", "-d", "redis"]
extend = "set-env-docker"
command = "docker"
args = ["compose", "down", "-v"]

[tasks.compose-remove]
extend = "set-env-docker"
command = "docker"
args = ["compose", "down", "-v"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP TRIGGER IF EXISTS books_updated_at_trigger ON books;
DROP TABLE IF EXISTS books;

DROP FUNCTION IF EXISTS set_updated_at;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE OR REPLACE FUNCTION set_updated_at() RETURNS TRIGGER AS '
BEGIN
new.updated_at := ''now'';
return new;
END;
' LANGUAGE 'plpgsql';

CREATE TABLE IF NOT EXISTS books (
book_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
isbn VARCHAR(255) NOT NULL,
description VARCHAR(1024) NOT NULL,
created_at TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
);

CREATE TRIGGER books_updated_at_trigger
BEFORE UPDATE ON books FOR EACH ROW
EXECUTE PROCEDURE set_updated_at();
3 changes: 3 additions & 0 deletions sandbox/rusty-book-manager/kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
shared.workspace = true
async-trait.workspace = true
anyhow.workspace = true
uuid.workspace = true
1 change: 1 addition & 0 deletions sandbox/rusty-book-manager/kernel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod model;
pub mod repository;
1 change: 1 addition & 0 deletions sandbox/rusty-book-manager/kernel/src/model/book/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod event;
1 change: 1 addition & 0 deletions sandbox/rusty-book-manager/kernel/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod book;

0 comments on commit fa7b25f

Please sign in to comment.