Adds some db tests using sql mock and slightly reorganises to facilitate testing
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:
4
store/migrations/000001_create_action_table.down.sql
Normal file
4
store/migrations/000001_create_action_table.down.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
DROP TABLE IF EXISTS actions;
|
||||
DROP TABLE IF EXISTS plans;
|
||||
|
||||
DROP FUNCTION IF EXISTS trigger_set_timestamp;
|
||||
36
store/migrations/000001_create_action_table.up.sql
Normal file
36
store/migrations/000001_create_action_table.up.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS plans(
|
||||
plan_id serial PRIMARY KEY,
|
||||
plan_date DATE NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS actions(
|
||||
action_id serial PRIMARY KEY,
|
||||
action_description VARCHAR (500) NOT NULL,
|
||||
estimated_chunks SMALLINT,
|
||||
completed_chunks SMALLINT,
|
||||
completed_on TIMESTAMP WITH TIME ZONE,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
plan int REFERENCES plans(plan_id)
|
||||
);
|
||||
|
||||
|
||||
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();
|
||||
|
||||
CREATE TRIGGER set_updated
|
||||
BEFORE UPDATE ON plans
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE trigger_set_timestamp();
|
||||
Reference in New Issue
Block a user