Skip to content

Commit

Permalink
feat: add migrate version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
cukhoaimon committed Feb 1, 2024
1 parent 89b89c6 commit bad3565
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

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

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ migrate-up:
migrate-down:
migrate -path db/migration -database "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable" -verbose down

migrate-up1:
migrate -path db/migration -database "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable" -verbose up 1

migrate-down1:
migrate -path db/migration -database "postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable" -verbose down 1



sqlc:
sqlc generate

Expand Down
2 changes: 1 addition & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func NewServer(store db.Store) *Server {

// routing here
router.GET("/api/v1/account", server.listAccount)
router.POST("/api/v1/account", server.createAccount)
router.GET("/api/v1/account/:id", server.getAccount)
router.POST("/api/v1/account", server.createAccount)

router.POST("/api/v1/transfer", server.createTransfer)

Expand Down
5 changes: 5 additions & 0 deletions db/migration/000002_add_users.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE IF EXISTS "accounts" DROP CONSTRAINT IF EXISTS "owner_currency_key";

ALTER TABLE IF EXISTS "accounts" DROP CONSTRAINT IF EXISTS "accounts_owner_idx";

DROP TABLE IF EXISTS "users";
11 changes: 11 additions & 0 deletions db/migration/000002_add_users.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE "users" (
"username" varchar PRIMARY KEY,
"hashed_password" varchar NOT NULL,
"full_name" varchar NOT NULL,
"email" varchar UNIQUE NOT NULL,
"password_changed_at" timestamptz NOT NULL DEFAULT '0001-01-01 00:00:00Z',
"created_at" timestamptz NOT NULL DEFAULT (now())
);

--CREATE INDEX ON "accounts" ("owner", "currency");
ALTER TABLE "accounts" ADD CONSTRAINT "owner_currency_key" UNIQUE ("owner", "currency");

0 comments on commit bad3565

Please sign in to comment.