Last active
December 4, 2015 04:46
-
-
Save jl-/82b14cfce9b7fea4db0e to your computer and use it in GitHub Desktop.
xixi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE xixi; | |
/** | |
* accounts | |
*/ | |
CREATE TABLE accounts ( | |
id bigserial UNIQUE NOT NULL, | |
-- UNIQUE is needed | |
-- http://www.postgresql.org/docs/9.5/static/datatype-numeric.html#DATATYPE-SERIAL | |
-- | |
username varchar(100) UNIQUE NOT NULL, | |
-- /^[A-Za-z][\w-]{1,31}$/ | |
email varchar(100) UNIQUE NOT NULL, | |
phone varchar(32) UNIQUE, | |
password varchar(100) NOT NULL, | |
-- /^[\w-@*#]{6,32}$/ | |
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP, | |
community_id serial, | |
location_id serial NOT NULL, | |
PRIMARY KEY (id), | |
FOREIGN KEY (location_id) REFERENCES locations(id), | |
FOREIGN KEY (community_id) REFERENCES communities(id), | |
); | |
/** | |
* communities | |
*/ | |
CREATE TABLE communities ( | |
id serial UNIQUE NOT NULL, | |
location_id serial UNIQUE NOT NULL, | |
PRIMARY KEY (id), | |
FOREIGN KEY (location_id) REFERENCES locations(id) | |
); | |
/** | |
* locations | |
*/ | |
CREATE TABLE locations ( | |
id serial UNIQUE NOT NULL, | |
--country, | |
--province, | |
--city, | |
--latitude, | |
--longitude, | |
PRIMARY KEY (id) | |
); | |
/** | |
* parents, | |
*/ | |
CREATE TABLE parents ( | |
account_id bigserial UNIQUE, | |
-- other parent-related infos | |
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE | |
--CONSTRANT parent_account_id FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE | |
); | |
/** | |
* experts | |
*/ | |
CREATE TABLE experts ( | |
account_id bigserial UNIQUE, | |
-- other experts-related infos | |
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment