adds create and update time to actions
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good

This commit is contained in:
2020-12-26 15:04:51 -06:00
parent 3a5961f003
commit 2c5e84d836
4 changed files with 35 additions and 11 deletions

View File

@@ -1 +1,3 @@
DROP TABLE IF EXISTS actions;
DROP FUNCTION IF EXISTS trigger_set_timestamp;

View File

@@ -1,4 +1,20 @@
CREATE TABLE IF NOT EXISTS actions(
id serial PRIMARY KEY,
description VARCHAR (500)
description VARCHAR (500),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $set_updated$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$set_updated$ LANGUAGE plpgsql;
CREATE TRIGGER set_updated
BEFORE UPDATE ON actions
FOR EACH ROW
EXECUTE PROCEDURE trigger_set_timestamp();

View File

@@ -61,7 +61,7 @@ func GetStore() *postgresStore {
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
actions := make([]*models.Action, 0)
err := store.db.Select(&actions, "SELECT id, description FROM actions")
err := store.db.Select(&actions, "SELECT id, description, created_at AS createdat, updated_at AS updatedat FROM actions")
if err != nil {
return nil, err
}

View File

@@ -1,10 +1,16 @@
package models
type Action struct {
ID int64
Description string
}
func (m *Model) Actions() ([]*Action, error) {
return m.SelectActions()
}
import (
"time"
)
type Action struct {
ID int64
Description string
CreatedAt time.Time
UpdatedAt time.Time
}
func (m *Model) Actions() ([]*Action, error) {
return m.SelectActions()
}