30 lines
796 B
PL/PgSQL
30 lines
796 B
PL/PgSQL
CREATE OR REPLACE PROCEDURE create_tables() AS $$
|
|
DROP TABLE IF EXISTS artist_website;
|
|
DROP TABLE IF EXISTS website;
|
|
DROP TABLE IF EXISTS artist;
|
|
|
|
CREATE TABLE IF NOT EXISTS artist (
|
|
id serial PRIMARY KEY,
|
|
name text NOT NULL,
|
|
CONSTRAINT a_name UNIQUE(name)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS website (
|
|
id serial PRIMARY KEY,
|
|
name text NOT NULL,
|
|
CONSTRAINT w_name UNIQUE(name)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS artist_website (
|
|
id serial PRIMARY KEY,
|
|
url text NOT NULL,
|
|
folder_path text,
|
|
website_id integer,
|
|
artist_id integer,
|
|
CONSTRAINT aw_url UNIQUE(url),
|
|
CONSTRAINT aw_folder_path UNIQUE(folder_path),
|
|
CONSTRAINT aw_artist FOREIGN KEY (artist_id) REFERENCES artist (ID),
|
|
CONSTRAINT aw_website FOREIGN KEY (website_id) REFERENCES website (ID)
|
|
);
|
|
$$ LANGUAGE SQL;
|