Rename updated and created

This commit is contained in:
Nicolas Duhamel 2016-02-24 13:34:55 +01:00
parent d4b1fb725c
commit c235eda1b0
2 changed files with 10 additions and 10 deletions

View File

@ -4,13 +4,13 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE OR REPLACE FUNCTION update_modified_column() CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$ RETURNS TRIGGER AS $$
BEGIN BEGIN
NEW.updated = now(); NEW.updated_at = now();
RETURN NEW; RETURN NEW;
END; $$ language 'plpgsql'; END; $$ language 'plpgsql';
CREATE TABLE base ( CREATE TABLE base (
updated timestamp DEFAULT current_timestamp, updated_at timestamp DEFAULT current_timestamp,
created timestamp DEFAULT current_timestamp created_at timestamp DEFAULT current_timestamp
); );
CREATE TABLE users ( CREATE TABLE users (
@ -19,7 +19,7 @@ CREATE TABLE users (
hash text NOT NULL, hash text NOT NULL,
LIKE base INCLUDING DEFAULTS LIKE base INCLUDING DEFAULTS
); );
CREATE TRIGGER update_users BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); CREATE TRIGGER update_users_updated_at BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
CREATE TABLE tokens ( CREATE TABLE tokens (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
@ -27,7 +27,7 @@ CREATE TABLE tokens (
users_id uuid REFERENCES users (id) ON DELETE CASCADE, users_id uuid REFERENCES users (id) ON DELETE CASCADE,
LIKE base INCLUDING DEFAULTS LIKE base INCLUDING DEFAULTS
); );
CREATE TRIGGER update_tokens BEFORE UPDATE ON tokens FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); CREATE TRIGGER update_tokens_updated_at BEFORE UPDATE ON tokens FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
CREATE TABLE shows ( CREATE TABLE shows (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
@ -41,7 +41,7 @@ CREATE TABLE shows (
LIKE base INCLUDING DEFAULTS LIKE base INCLUDING DEFAULTS
); );
CREATE INDEX ON shows (imdbid); CREATE INDEX ON shows (imdbid);
CREATE TRIGGER update_shows BEFORE UPDATE ON shows FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); CREATE TRIGGER update_shows_updated_at BEFORE UPDATE ON shows FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
CREATE TABLE episodes ( CREATE TABLE episodes (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
@ -59,7 +59,7 @@ CREATE TABLE episodes (
); );
CREATE INDEX ON episodes (shows_id, season); CREATE INDEX ON episodes (shows_id, season);
CREATE INDEX ON episodes (shows_id, season, episode); CREATE INDEX ON episodes (shows_id, season, episode);
CREATE TRIGGER update_episodes BEFORE UPDATE ON episodes FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); CREATE TRIGGER update_episodes_updated_at BEFORE UPDATE ON episodes FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
CREATE TABLE shows_tracked ( CREATE TABLE shows_tracked (
shows_id uuid NOT NULL REFERENCES shows (id) ON DELETE CASCADE, shows_id uuid NOT NULL REFERENCES shows (id) ON DELETE CASCADE,
@ -86,4 +86,4 @@ CREATE TABLE movies (
LIKE base INCLUDING DEFAULTS LIKE base INCLUDING DEFAULTS
); );
CREATE INDEX ON movies (imdbid); CREATE INDEX ON movies (imdbid);
CREATE TRIGGER update_movies BEFORE UPDATE ON movies FOR EACH ROW EXECUTE PROCEDURE update_modified_column(); CREATE TRIGGER update_movies_updated_at BEFORE UPDATE ON movies FOR EACH ROW EXECUTE PROCEDURE update_modified_column();

View File

@ -12,8 +12,8 @@ import (
// BaseModel have to be embeded in all your struct which reflect a table // BaseModel have to be embeded in all your struct which reflect a table
type BaseModel struct { type BaseModel struct {
ID string ID string
Updated time.Time Updated time.Time `db:"updated_at"`
Created time.Time Created time.Time `db:"created_at"`
} }
// RunWithLastestMigration runs your test with database migration set to the lastest // RunWithLastestMigration runs your test with database migration set to the lastest