adds create and update time to actions
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
DROP TABLE IF EXISTS actions;
|
DROP TABLE IF EXISTS actions;
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS trigger_set_timestamp;
|
||||||
|
|||||||
@@ -1,4 +1,20 @@
|
|||||||
CREATE TABLE IF NOT EXISTS actions(
|
CREATE TABLE IF NOT EXISTS actions(
|
||||||
id serial PRIMARY KEY,
|
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();
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func GetStore() *postgresStore {
|
|||||||
|
|
||||||
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
|
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
|
||||||
actions := make([]*models.Action, 0)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type Action struct {
|
import (
|
||||||
ID int64
|
"time"
|
||||||
Description string
|
)
|
||||||
}
|
|
||||||
|
type Action struct {
|
||||||
func (m *Model) Actions() ([]*Action, error) {
|
ID int64
|
||||||
return m.SelectActions()
|
Description string
|
||||||
}
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) Actions() ([]*Action, error) {
|
||||||
|
return m.SelectActions()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user