Skip to content

Commit

Permalink
feat: add enum type to forum example
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Apr 16, 2016
1 parent eb4d987 commit 28e6126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
49 changes: 21 additions & 28 deletions examples/forum/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
begin;

-- Create the schema we are going to use.
create schema if not exists forum_example;
create schema forum_example;

-- By setting the `search_path`, whenever we create something in the default
-- namespace it is actually created in the `blog_example` schema.
--
-- For example, this lets us write `create table person …` instead of
-- `create table blog_example.person …`.
-- `create table forum_example.person …`.
set search_path = forum_example;

-------------------------------------------------------------------------------
-- Basic Tables

create table if not exists person (
create table person (
id serial not null primary key,
given_name varchar(64) not null,
family_name varchar(64),
Expand All @@ -28,10 +28,13 @@ comment on column person.given_name is 'The person’s first name.';
comment on column person.family_name is 'The person’s last name.';
comment on column person.about is 'A short description about the user, written by the user.';

create table if not exists post (
create type post_topic as enum ('discussion', 'inspiration', 'help');

create table post (
id serial not null primary key,
author_id int not null references person(id),
headline text not null,
topic post_topic,
body text
);

Expand All @@ -58,31 +61,21 @@ insert into person (id, given_name, family_name, about) values
(11, 'Beverly', 'Kelly', null),
(12, 'Kelly', 'Reed', null),
(13, 'Nicholas', 'Perry', null),
(14, 'Carol', 'Taylor', null)
on conflict (id) do
update set
given_name = excluded.given_name,
family_name = excluded.family_name,
about = excluded.about;
(14, 'Carol', 'Taylor', null);

insert into post (id, author_id, headline, body) values
(1, 2, 'No… It’s a thing; it’s like a plan, but with more greatness.', null),
(2, 1, 'I hate yogurt. It’s just stuff with bits in.', null),
(3, 1, 'Is that a cooking show?', null),
(4, 1, 'You hit me with a cricket bat.', null),
(5, 5, 'Please, Don-Bot… look into your hard drive, and open your mercy file!', null),
(6, 3, 'Stop talking, brain thinking. Hush.', null),
(7, 1, 'Large bet on myself in round one.', null),
(8, 2, 'It’s a fez. I wear a fez now. Fezes are cool.', null),
(9, 3, 'You know how I sometimes have really brilliant ideas?', null),
(10, 2, 'What’s with you kids? Every other day it’s food, food, food.', null),
(11, 3, 'They’re not aliens, they’re Earth…liens!', null),
(12, 5, 'You’ve swallowed a planet!', null)
on conflict (id) do
update set
author_id = excluded.author_id,
headline = excluded.headline,
body = excluded.body;
insert into post (id, author_id, headline, topic, body) values
(1, 2, 'No… It’s a thing; it’s like a plan, but with more greatness.', null, null),
(2, 1, 'I hate yogurt. It’s just stuff with bits in.', 'inspiration', null),
(3, 1, 'Is that a cooking show?', 'inspiration', null),
(4, 1, 'You hit me with a cricket bat.', null, null),
(5, 5, 'Please, Don-Bot… look into your hard drive, and open your mercy file!', null, null),
(6, 3, 'Stop talking, brain thinking. Hush.', null, null),
(7, 1, 'Large bet on myself in round one.', 'discussion', null),
(8, 2, 'It’s a fez. I wear a fez now. Fezes are cool.', 'inspiration', null),
(9, 3, 'You know how I sometimes have really brilliant ideas?', null, null),
(10, 2, 'What’s with you kids? Every other day it’s food, food, food.', 'discussion', null),
(11, 3, 'They’re not aliens, they’re Earth…liens!', 'help', null),
(12, 5, 'You’ve swallowed a planet!', null, null);

-------------------------------------------------------------------------------
-- Permissions
Expand Down
2 changes: 0 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash

npm run schema-up

babel-watch --watch src \
src/main.js -- postgres://localhost:5432 --schema forum_example --development

0 comments on commit 28e6126

Please sign in to comment.