Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'flips'

  • Loading branch information...
commit e161a90f6863006be4930c77addcde84d2367b5c 2 parents 2fae0b3 + 54d680f
@theory authored
View
12 sql/deploy/delete_flip.sql
@@ -0,0 +1,12 @@
+-- requires: flips, appuser
+BEGIN;
+CREATE OR REPLACE FUNCTION delete_flip(
+ flip_id BIGINT
+) RETURNS BOOLEAN LANGUAGE plpgsql SECURITY DEFINER AS $$
+BEGIN
+ DELETE FROM flips WHERE id = flip_id;
+ RETURN FOUND;
+END;
+$$;
+GRANT EXECUTE ON FUNCTION delete_flip(BIGINT) to flipr;
+COMMIT;
View
16 sql/deploy/flips.sql
@@ -0,0 +1,16 @@
+-- requires: users
+
+BEGIN;
+
+SET client_min_messages = 'warning';
+
+CREATE TABLE flips (
+ id BIGSERIAL PRIMARY KEY,
+ nickname TEXT NOT NULL REFERENCES users(nickname),
+ body TEXT NOT NULL DEFAULT '' CHECK ( length(body) <= 180 ),
+ timestamp TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp()
+);
+
+GRANT SELECT ON flips TO flipr;
+
+COMMIT;
View
12 sql/deploy/insert_flip.sql
@@ -0,0 +1,12 @@
+-- requires: flips, appuser
+BEGIN;
+CREATE OR REPLACE FUNCTION insert_flip(
+ nickname TEXT,
+ body TEXT
+) RETURNS BIGINT LANGUAGE sql SECURITY DEFINER AS $$
+ INSERT INTO flips (body, nickname)
+ VALUES ($1, $2)
+ RETURNING id;
+$$;
+GRANT EXECUTE ON FUNCTION insert_flip(TEXT, TEXT) to flipr;
+COMMIT;
View
1  sql/revert/delete_flip.sql
@@ -0,0 +1 @@
+DROP FUNCTION delete_flip(BIGINT);
View
2  sql/revert/flips.sql
@@ -0,0 +1,2 @@
+DROP TABLE flips;
+
View
1  sql/revert/insert_flip.sql
@@ -0,0 +1 @@
+DROP FUNCTION insert_flip(TEXT, TEXT);
Please sign in to comment.
Something went wrong with that request. Please try again.