Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrations scripts #78

Merged
merged 9 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/bun/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"path/filepath"
"strings"

"github.com/Real-Dev-Squad/tiny-site-backend/cmd/bun/migrations"
"github.com/Real-Dev-Squad/tiny-site-backend/utils"
"github.com/uptrace/bun/example/migrate/migrations"
"github.com/uptrace/bun/migrate"
"github.com/urfave/cli/v2"
)
Expand Down
13 changes: 13 additions & 0 deletions cmd/bun/migrations/20240215113820_initial-setup.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;

--bun:split

DROP TABLE IF EXISTS users;

--bun:split

DROP TABLE IF EXISTS tiny_url;

--bun:split

COMMIT;
34 changes: 34 additions & 0 deletions cmd/bun/migrations/20240215113820_initial-setup.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BEGIN;

--bun:split

CREATE TABLE users (
id bigserial PRIMARY KEY,
username varchar(256) UNIQUE NOT NULL,
email varchar UNIQUE NOT NULL,
is_verified boolean DEFAULT false,
password varchar(128) NOT NULL,
created_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC'),
updated_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC'),
is_deleted boolean DEFAULT false,
is_onboarding BOOLEAN NOT NULL DEFAULT TRUE
);

--bun:split

CREATE TABLE tiny_url (
id bigserial PRIMARY KEY,
original_url text NOT NULL,
short_url text UNIQUE NOT NULL,
comment text,
user_id int NOT NULL REFERENCES users(id),
expired_at timestamp NOT NULL,
created_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC'),
created_by text NOT NULL,
access_count bigint DEFAULT 0,
last_accessed_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC')
);

--bun:split

COMMIT;
10 changes: 9 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ services:
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
expose:
- 5432
ports:
- 5432:5432
healthcheck:
test: [ "CMD", "pg_isready" ]
test: [ "CMD", "pg_isready -U $$POSTGRES_USER $$POSTGRES_DB" ]
interval: 10s
timeout: 5s
retries: 5

adminer:
image: adminer
ports:
- 9091:8080

# volumes:
# db-data:
# secrets:
Expand Down
Loading