From fac1a7fe6941c3200e39bfbbdf71090c710aaa8e Mon Sep 17 00:00:00 2001 From: Patrick O'brien Date: Sat, 7 Jan 2017 01:17:28 +1000 Subject: [PATCH] update schemas to incl broken example from readme --- testdata/mysql_test_schema.sql | 69 ++++++++++++++++--------------- testdata/postgres_test_schema.sql | 69 ++++++++++++++++--------------- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/testdata/mysql_test_schema.sql b/testdata/mysql_test_schema.sql index a3b4af4..4755a63 100644 --- a/testdata/mysql_test_schema.sql +++ b/testdata/mysql_test_schema.sql @@ -240,40 +240,6 @@ create table worms ( foreign key (tiger_id) references tigers (id) ); -create table pilots ( - id int primary key not null auto_increment, - name varchar(255) -); - -create table airports ( - id int primary key not null auto_increment, - name varchar(255) -); - -create table languages ( - id int primary key not null auto_increment, - name varchar(255) -); - -create table jets ( - id int primary key not null auto_increment, - name varchar(255), - pilot_id integer, - airport_id integer, - - foreign key (pilot_id) references pilots (id), - foreign key (airport_id) references airports (id) -); - -create table pilot_languages ( - pilot_id integer not null, - language_id integer not null, - - primary key (pilot_id, language_id), - foreign key (pilot_id) references pilots (id), - foreign key (language_id) references languages (id) -); - create table byte_pilots ( id binary primary key not null, name varchar(255) @@ -351,3 +317,38 @@ CREATE TABLE race_result_scratchings ( foreign key (results_id) references race_results(id) ); +CREATE TABLE pilots ( + id integer NOT NULL, + name text NOT NULL +); + +ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id); + +CREATE TABLE jets ( + id integer NOT NULL, + pilot_id integer NOT NULL, + age integer NOT NULL, + name text NOT NULL, + color text NOT NULL +); + +ALTER TABLE jets ADD CONSTRAINT jet_pkey PRIMARY KEY (id); +ALTER TABLE jets ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id); + +CREATE TABLE languages ( + id integer NOT NULL, + language text NOT NULL +); + +ALTER TABLE languages ADD CONSTRAINT language_pkey PRIMARY KEY (id); + +-- Join table +CREATE TABLE pilot_languages ( + pilot_id integer NOT NULL, + language_id integer NOT NULL +); + +-- Composite primary key +ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pkey PRIMARY KEY (pilot_id, language_id); +ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id); +ALTER TABLE pilot_languages ADD CONSTRAINT languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id); diff --git a/testdata/postgres_test_schema.sql b/testdata/postgres_test_schema.sql index 7a3893e..52f33e4 100644 --- a/testdata/postgres_test_schema.sql +++ b/testdata/postgres_test_schema.sql @@ -246,7 +246,6 @@ create table enemies ( primary key (enemies) ); - create table chocolate ( dog varchar(100) primary key ); @@ -307,38 +306,6 @@ create table worms ( foreign key (tiger_id) references tigers (id) ); -create table pilots ( - id serial primary key not null, - name character varying -); - -create table airports ( - id serial primary key not null, - name character varying -); - -create table languages ( - id serial primary key not null, - name character varying -); - -create table jets ( - id serial primary key not null, - name character varying, - pilot_id integer, - airport_id integer, - foreign key (pilot_id) references pilots (id), - foreign key (airport_id) references airports (id) -); - -create table pilot_languages ( - pilot_id integer not null, - language_id integer not null, - - primary key (pilot_id, language_id), - foreign key (pilot_id) references pilots (id), - foreign key (language_id) references languages (id) -); create table byte_pilots ( id bytea primary key not null, @@ -416,3 +383,39 @@ CREATE TABLE race_result_scratchings ( name text NOT NULL, foreign key (results_id) references race_results(id) ); + +CREATE TABLE pilots ( + id integer NOT NULL, + name text NOT NULL +); + +ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id); + +CREATE TABLE jets ( + id integer NOT NULL, + pilot_id integer NOT NULL, + age integer NOT NULL, + name text NOT NULL, + color text NOT NULL +); + +ALTER TABLE jets ADD CONSTRAINT jet_pkey PRIMARY KEY (id); +ALTER TABLE jets ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id); + +CREATE TABLE languages ( + id integer NOT NULL, + language text NOT NULL +); + +ALTER TABLE languages ADD CONSTRAINT language_pkey PRIMARY KEY (id); + +-- Join table +CREATE TABLE pilot_languages ( + pilot_id integer NOT NULL, + language_id integer NOT NULL +); + +-- Composite primary key +ALTER TABLE pilot_languages ADD CONSTRAINT pilot_language_pkey PRIMARY KEY (pilot_id, language_id); +ALTER TABLE pilot_languages ADD CONSTRAINT pilots_fkey FOREIGN KEY (pilot_id) REFERENCES pilots(id); +ALTER TABLE pilot_languages ADD CONSTRAINT languages_fkey FOREIGN KEY (language_id) REFERENCES languages(id);