]> git.datanom.net - pwp.git/blame - app/DB/db_mysql.sql
Half way through migration away from sqlalchemy
[pwp.git] / app / DB / db_mysql.sql
CommitLineData
e5424f29
MR
1DROP TABLE IF EXISTS photo,format,album,portfolio,accessright,role,user;
2CREATE TABLE user
3(
4 id integer NOT NULL AUTO_INCREMENT,
5 name varchar(255) NOT NULL,
6 email varchar(150) NOT NULL,
7 username varchar(150) NOT NULL,
8 password varchar(255) NOT NULL,
9 CONSTRAINT user_pkey PRIMARY KEY (id)
10) ENGINE = InnoDB;
11
12DROP INDEX IF EXISTS ix_user_email ON user;
13CREATE UNIQUE INDEX ix_user_email ON user (email);
14
15DROP INDEX IF EXISTS ix_user_username ON user;
16CREATE UNIQUE INDEX ix_user_username ON user (username);
17
18CREATE TABLE role
19(
20 id integer NOT NULL AUTO_INCREMENT,
21 role varchar(255),
22 CONSTRAINT role_pkey PRIMARY KEY (id)
23) ENGINE = InnoDB;
24insert into role (role) values ('read');
25insert into role (role) values ('write');
26insert into role (role) values ('admin');
27
28CREATE TABLE accessright
29(
30 id integer NOT NULL AUTO_INCREMENT,
31 perm integer NOT NULL,
32 user integer NOT NULL,
33 CONSTRAINT accessright_pkey PRIMARY KEY (id),
34 CONSTRAINT accessright_userid_fkey FOREIGN KEY (user)
35 REFERENCES user (id) MATCH SIMPLE
36 ON UPDATE CASCADE ON DELETE CASCADE,
37 CONSTRAINT accessright_perm_fkey FOREIGN KEY (perm)
38 REFERENCES role (id) MATCH SIMPLE
39 ON UPDATE CASCADE ON DELETE CASCADE
40) ENGINE = InnoDB;
41
42CREATE TABLE portfolio
43(
44 id integer NOT NULL AUTO_INCREMENT,
45 name varchar(255),
46 user integer NOT NULL,
47 public boolean NOT NULL DEFAULT true,
48 visible boolean NOT NULL DEFAULT true,
49 CONSTRAINT portfolio_pkey PRIMARY KEY (id),
50 CONSTRAINT portfolio_userid_fkey FOREIGN KEY (user)
51 REFERENCES user (id) MATCH SIMPLE
52 ON UPDATE CASCADE ON DELETE CASCADE
53) ENGINE = InnoDB;
54
55CREATE TABLE album
56(
57 id integer NOT NULL AUTO_INCREMENT,
58 name varchar(255),
59 visible boolean NOT NULL,
60 public boolean NOT NULL,
fc01a3eb 61 portfolio integer NOT NULL,
e5424f29 62 CONSTRAINT album_pkey PRIMARY KEY (id),
fc01a3eb 63 CONSTRAINT album_portfolio_fkey FOREIGN KEY (portfolio)
e5424f29
MR
64 REFERENCES portfolio (id) MATCH SIMPLE
65 ON UPDATE CASCADE ON DELETE CASCADE
66) ENGINE = InnoDB;
67
68CREATE TABLE format
69(
70 id integer NOT NULL AUTO_INCREMENT,
71 format varchar(255),
72 CONSTRAINT format_pkey PRIMARY KEY (id)
73) ENGINE = InnoDB;
74insert into format (format) values ('jpg');
75insert into format (format) values ('raw');
76insert into format (format) values ('tiff');
77
78CREATE TABLE photo
79(
80 id integer NOT NULL AUTO_INCREMENT,
81 file varchar(255),
82 name varchar(255),
83 exif varchar(255),
84 format integer NOT NULL,
fc01a3eb 85 album integer NOT NULL,
e5424f29
MR
86 visible boolean NOT NULL,
87 public boolean NOT NULL,
88 CONSTRAINT photo_pkey PRIMARY KEY (id),
fc01a3eb 89 CONSTRAINT photo_album_fkey FOREIGN KEY (album)
e5424f29
MR
90 REFERENCES album (id) MATCH SIMPLE
91 ON UPDATE CASCADE ON DELETE CASCADE,
92 CONSTRAINT photo_format_fkey FOREIGN KEY (format)
93 REFERENCES format (id) MATCH SIMPLE
94 ON UPDATE CASCADE ON DELETE CASCADE
95) ENGINE = InnoDB;
96
This page took 0.050864 seconds and 5 git commands to generate.