Reverting init.sql.
This commit is contained in:
parent
f0da4b0366
commit
8a64dd1e0a
|
@ -1,35 +1,92 @@
|
||||||
-- Create the first table
|
SELECT 'CREATE DATABASE main'
|
||||||
CREATE TABLE first_table (
|
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
||||||
id SERIAL PRIMARY KEY,
|
CREATE SCHEMA "test-1";
|
||||||
name VARCHAR(255) NOT NULL,
|
CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer', 'support');
|
||||||
description TEXT
|
CREATE TABLE Persons (
|
||||||
|
PersonID SERIAL PRIMARY KEY,
|
||||||
|
LastName varchar(255),
|
||||||
|
FirstName varchar(255),
|
||||||
|
Address varchar(255),
|
||||||
|
City varchar(255) DEFAULT 'Belfast',
|
||||||
|
Age INTEGER DEFAULT 20 NOT NULL,
|
||||||
|
Year INTEGER,
|
||||||
|
Type person_job
|
||||||
);
|
);
|
||||||
|
CREATE TABLE Tasks (
|
||||||
-- Create the second table
|
TaskID SERIAL PRIMARY KEY,
|
||||||
CREATE TABLE second_table (
|
ExecutorID INT,
|
||||||
id SERIAL PRIMARY KEY,
|
QaID INT,
|
||||||
first_table_id INT REFERENCES first_table(id),
|
Completed BOOLEAN,
|
||||||
data TEXT NOT NULL
|
TaskName varchar(255),
|
||||||
|
CONSTRAINT fkexecutor
|
||||||
|
FOREIGN KEY(ExecutorID)
|
||||||
|
REFERENCES Persons(PersonID),
|
||||||
|
CONSTRAINT fkqa
|
||||||
|
FOREIGN KEY(QaID)
|
||||||
|
REFERENCES Persons(PersonID)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE Products (
|
||||||
|
ProductID SERIAL PRIMARY KEY,
|
||||||
|
ProductName varchar(255)
|
||||||
|
);
|
||||||
|
CREATE TABLE Products_Tasks (
|
||||||
|
ProductID INT NOT NULL,
|
||||||
|
TaskID INT NOT NULL,
|
||||||
|
CONSTRAINT fkProducts
|
||||||
|
FOREIGN KEY(ProductID)
|
||||||
|
REFERENCES Products(ProductID),
|
||||||
|
CONSTRAINT fkTasks
|
||||||
|
FOREIGN KEY(TaskID)
|
||||||
|
REFERENCES Tasks(TaskID),
|
||||||
|
PRIMARY KEY (ProductID, TaskID)
|
||||||
|
);
|
||||||
|
CREATE TABLE "test-1".table1 (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
Name varchar(255)
|
||||||
|
);
|
||||||
|
CREATE TABLE CompositeTable (
|
||||||
|
KeyPartOne varchar(128),
|
||||||
|
KeyPartTwo varchar(128),
|
||||||
|
Name varchar(255),
|
||||||
|
PRIMARY KEY (KeyPartOne, KeyPartTwo)
|
||||||
|
);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Year) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast', 'qa', 1999);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Year) VALUES ('John', 'Smith', '64 Updown Road', 'Dublin', 'programmer', 1996);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Foo', 'Bar', 'Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type) VALUES ('Jonny', 'Muffin', 'Muffin Street', 'Cork', 'support');
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Dave', 'Bar', '2 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('James', 'Bar', '3 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Jenny', 'Bar', '4 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Grace', 'Bar', '5 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Sarah', 'Bar', '6 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
INSERT INTO Persons (FirstName, LastName, Address, City, Type, Age, Year) VALUES ('Kelly', 'Bar', '7 Foo Street', 'Bartown', 'support', 0, 1993);
|
||||||
|
|
||||||
-- Insert 50 rows into the first table
|
-- insert a lot of tasks for testing
|
||||||
DO
|
WITH RECURSIVE generate_series AS (
|
||||||
$$
|
SELECT 1 AS n
|
||||||
BEGIN
|
UNION ALL
|
||||||
FOR i IN 1..50 LOOP
|
SELECT n + 1 FROM generate_series WHERE n < 6000
|
||||||
INSERT INTO first_table (name, description)
|
),
|
||||||
VALUES ('Name ' || i, 'Description ' || i);
|
random_data AS (
|
||||||
END LOOP;
|
SELECT
|
||||||
END
|
n,
|
||||||
$$;
|
(random() * 9 + 1)::int AS ExecutorID,
|
||||||
|
(random() * 9 + 1)::int AS QaID,
|
||||||
-- Insert 10,000 rows into the second table, all related to the first row in the first table
|
'assembling' AS TaskName,
|
||||||
DO
|
(random() < 0.5) AS Completed
|
||||||
$$
|
FROM generate_series
|
||||||
BEGIN
|
)
|
||||||
FOR i IN 1..10000 LOOP
|
INSERT INTO Tasks (ExecutorID, QaID, TaskName, Completed)
|
||||||
INSERT INTO second_table (first_table_id, data)
|
SELECT ExecutorID, QaID, TaskName, Completed
|
||||||
VALUES (1, 'Data ' || i);
|
FROM random_data;
|
||||||
END LOOP;
|
INSERT INTO Products (ProductName) VALUES ('Computers');
|
||||||
END
|
INSERT INTO Products (ProductName) VALUES ('Laptops');
|
||||||
$$;
|
INSERT INTO Products (ProductName) VALUES ('Chairs');
|
||||||
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 1);
|
||||||
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (2, 1);
|
||||||
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (3, 1);
|
||||||
|
INSERT INTO Products_Tasks (ProductID, TaskID) VALUES (1, 2);
|
||||||
|
INSERT INTO "test-1".table1 (Name) VALUES ('Test');
|
||||||
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('aaa', 'bbb', 'Michael');
|
||||||
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('bbb', 'ccc', 'Andrew');
|
||||||
|
INSERT INTO CompositeTable (KeyPartOne, KeyPartTwo, Name) VALUES ('ddd', '', 'OneKey');
|
Loading…
Reference in New Issue