Use pug
This commit is contained in:
1
sql/migrations/applied.sql
Normal file
1
sql/migrations/applied.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT id, name, applied_at FROM migrations ORDER BY applied_at
|
||||
1
sql/migrations/apply.sql
Normal file
1
sql/migrations/apply.sql
Normal file
@@ -0,0 +1 @@
|
||||
INSERT INTO migrations (name) VALUES ($1);
|
||||
5
sql/migrations/create.sql
Normal file
5
sql/migrations/create.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS migrations (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text UNIQUE NOT NULL,
|
||||
applied_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
DROP FUNCTION set_updated_timestamp;
|
||||
11
sql/migrations/patches/20190925000000-updated-at/up.sql
Normal file
11
sql/migrations/patches/20190925000000-updated-at/up.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE OR REPLACE FUNCTION set_updated_timestamp()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
ELSE
|
||||
RETURN OLD;
|
||||
END IF;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
1
sql/migrations/patches/20190925000001-users/down.sql
Normal file
1
sql/migrations/patches/20190925000001-users/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE users;
|
||||
9
sql/migrations/patches/20190925000001-users/up.sql
Normal file
9
sql/migrations/patches/20190925000001-users/up.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE users (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
email text NOT NULL UNIQUE,
|
||||
encrypted_password text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TRIGGER set_users_updated BEFORE UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE set_updated_timestamp();
|
||||
1
sql/users/create.sql
Normal file
1
sql/users/create.sql
Normal file
@@ -0,0 +1 @@
|
||||
INSERT INTO users (email, encrypted_password) VALUES ($1, $2) RETURNING id
|
||||
1
sql/users/login.sql
Normal file
1
sql/users/login.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT id, encrypted_password FROM users WHERE email=$1
|
||||
Reference in New Issue
Block a user