2022-08-23 09:01:47 +09:00
|
|
|
-- migrate:up
|
2022-08-28 22:33:19 +09:00
|
|
|
CREATE ROLE anon;
|
|
|
|
ALTER ROLE anon SET statement_timeout = '1s';
|
|
|
|
|
2022-08-23 09:01:47 +09:00
|
|
|
CREATE FUNCTION update_timestamp() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
|
|
BEGIN
|
|
|
|
NEW.updated = CURRENT_TIMESTAMP;
|
|
|
|
RETURN NEW;
|
|
|
|
END
|
|
|
|
$$;
|
|
|
|
|
|
|
|
CREATE TABLE pages (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
title TEXT NOT NULL UNIQUE,
|
|
|
|
text TEXT NOT NULL,
|
|
|
|
created TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);
|
|
|
|
|
2022-08-28 22:33:19 +09:00
|
|
|
GRANT ALL ON pages TO anon;
|
|
|
|
|
2022-08-23 09:01:47 +09:00
|
|
|
CREATE TRIGGER pages_updated BEFORE UPDATE ON pages FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE update_timestamp();
|
|
|
|
|
|
|
|
-- migrate:down
|
|
|
|
DROP TABLE pages;
|
|
|
|
DROP FUNCTION update_timestamp();
|
2022-08-28 22:33:19 +09:00
|
|
|
DROP ROLE anon;
|