ekster/cmd/eksterd/db/migrations/000008_create_table_sources.up.sql
Peter Stuifzand caaa069660
All checks were successful
continuous-integration/drone/push Build is passing
Problem: no sources in database
Solution: add sources in database and tests
2022-04-20 13:22:06 +02:00

21 lines
549 B
PL/PgSQL

BEGIN;
CREATE OR REPLACE FUNCTION update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
COMMIT;
CREATE TABLE "sources" (
"id" int primary key generated always as identity,
"channel_id" int not null,
"auth_code" varchar(64) not null,
"created_at" timestamp DEFAULT current_timestamp,
"updated_at" timestamp DEFAULT current_timestamp
);
CREATE TRIGGER sources_update_timestamp BEFORE INSERT OR UPDATE ON "sources"
FOR EACH ROW EXECUTE PROCEDURE update_timestamp();