refactor: 🗃️ Migrations to lc

This commit is contained in:
ThatOneCalculator 2022-04-03 22:39:26 -07:00
parent 3eb141ec72
commit a2b3104c08
4 changed files with 22 additions and 22 deletions

View File

@ -0,0 +1,21 @@
create table if not exists pastes (
"id" text primary key,
"content" text not null,
"views" bigint default 0,
"single_view" boolean default false,
"expires_at" timestamp without time zone,
"created_at" timestamp without time zone default(now() at time zone 'utc')
);
create or replace function deleteexpiredpastes() returns trigger as $pastes_expire$ begin
delete from pastes
where "expires_at" is not null
and "expires_at" < now() at time zone 'utc';
return new;
end;
$pastes_expire$ language plpgsql;
create trigger checkpastes before
insert
or
update on pastes for statement execute procedure deleteexpiredpastes();

View File

@ -1,21 +0,0 @@
CREATE TABLE IF NOT EXISTS pastes (
"id" TEXT PRIMARY KEY,
"content" TEXT NOT NULL,
"views" BIGINT DEFAULT 0,
"single_view" BOOLEAN DEFAULT false,
"expires_at" TIMESTAMP WITHOUT TIME ZONE,
"created_at" TIMESTAMP WITHOUT TIME ZONE DEFAULT(NOW() AT TIME ZONE 'utc')
);
CREATE OR REPLACE FUNCTION deleteExpiredPastes() RETURNS trigger AS $pastes_expire$ BEGIN
DELETE FROM pastes
WHERE "expires_at" IS NOT NULL
AND "expires_at" < now() AT TIME ZONE 'utc';
RETURN NEW;
END;
$pastes_expire$ LANGUAGE plpgsql;
CREATE TRIGGER checkPastes BEFORE
INSERT
OR
UPDATE ON pastes FOR STATEMENT EXECUTE PROCEDURE deleteExpiredPastes();

View File

@ -1 +0,0 @@
ALTER TABLE pastes ADD COLUMN single_view BOOLEAN DEFAULT false;

View File

@ -0,0 +1 @@
alter table pastes add column single_view boolean default false;