-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update and creat fields in schemas
- Loading branch information
1 parent
2e2d9a8
commit b8a06cf
Showing
5 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
backend/db/migrations/20240704123000_create_users_and_cards_tables.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,51 @@ | ||
-- +goose Up | ||
-- SQL in section 'Up' is executed when this migration is applied. | ||
|
||
CREATE TABLE users | ||
( | ||
id VARCHAR(255) PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE cards | ||
( | ||
id SERIAL PRIMARY KEY, | ||
front TEXT NOT NULL, | ||
back TEXT NOT NULL, | ||
review_date TIMESTAMP NOT NULL, | ||
interval_days INT NOT NULL DEFAULT 1, | ||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE | ||
OR REPLACE FUNCTION update_updated_at_column() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.updated | ||
= CURRENT_TIMESTAMP; | ||
RETURN NEW; | ||
END; | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER update_users_updated_at | ||
BEFORE UPDATE | ||
ON users | ||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); | ||
|
||
CREATE TRIGGER update_cards_updated_at | ||
BEFORE UPDATE | ||
ON cards | ||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); | ||
|
||
-- +goose Down | ||
-- SQL section 'Down' is executed when this migration is rolled back. | ||
|
||
DROP TRIGGER IF EXISTS update_users_updated_at ON users; | ||
DROP TRIGGER IF EXISTS update_cards_updated_at ON cards; | ||
DROP FUNCTION IF EXISTS update_updated_at_column; | ||
DROP TABLE IF EXISTS cards; | ||
DROP TABLE IF EXISTS users; |
23 changes: 0 additions & 23 deletions
23
backend/db/migrations/20240704123000_create_users_and_todos_tables.sql
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
package flashcard | ||
|
||
import "time" | ||
|
||
type Card struct { | ||
ID uint `gorm:"primaryKey"` | ||
Front string `gorm:"not null"` | ||
Back string `gorm:"not null"` | ||
ReviewDate time.Time `gorm:"not null"` | ||
IntervalDays int `gorm:"not null;default:1"` | ||
Created time.Time `gorm:"autoCreateTime"` | ||
Updated time.Time `gorm:"autoUpdateTime"` | ||
} |
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
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,12 @@ | ||
package flashcard | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type User struct { | ||
ID string `gorm:"primaryKey"` | ||
Name string `gorm:"not null"` | ||
Created time.Time `gorm:"autoCreateTime"` | ||
Updated time.Time `gorm:"autoUpdateTime"` | ||
} |