Skip to content

Commit

Permalink
postgres tests done
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi committed Dec 20, 2024
1 parent b8b87d7 commit d109f85
Show file tree
Hide file tree
Showing 16 changed files with 2,134 additions and 1,587 deletions.
10 changes: 10 additions & 0 deletions internal/testutil/testdata/gen_jobmappings_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"sql_file": "create-tables.sql",
"driver": "postgres"
},
{
"folder": "postgres/foreignkey-violations",
"sql_file": "create-tables.sql",
"driver": "postgres"
},
{
"folder": "postgres/subsetting",
"sql_file": "create-tables.sql",
"driver": "postgres"
},
{
"folder": "mysql/alltypes",
"sql_file": "create-tables.sql",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
set search_path to fk_violations;
CREATE TABLE IF NOT EXISTS regions (
region_id SERIAL PRIMARY KEY,
region_name CHARACTER VARYING (25)
);

CREATE TABLE IF NOT EXISTS countries (
country_id CHARACTER (2) PRIMARY KEY,
country_name CHARACTER VARYING (40),
region_id INTEGER NOT NULL,
FOREIGN KEY (region_id) REFERENCES regions (region_id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS locations (
location_id SERIAL PRIMARY KEY,
street_address CHARACTER VARYING (40),
postal_code CHARACTER VARYING (12),
city CHARACTER VARYING (30) NOT NULL,
state_province CHARACTER VARYING (25),
country_id CHARACTER (2) NOT NULL,
FOREIGN KEY (country_id) REFERENCES countries (country_id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS departments (
department_id SERIAL PRIMARY KEY,
department_name CHARACTER VARYING (30) NOT NULL,
location_id INTEGER,
FOREIGN KEY (location_id) REFERENCES locations (location_id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS jobs (
job_id SERIAL PRIMARY KEY,
job_title CHARACTER VARYING (35) NOT NULL,
min_salary NUMERIC (8, 2),
max_salary NUMERIC (8, 2)
);

CREATE TABLE IF NOT EXISTS employees (
employee_id SERIAL PRIMARY KEY,
first_name CHARACTER VARYING (20),
last_name CHARACTER VARYING (25) NOT NULL,
email CHARACTER VARYING (100) NOT NULL,
phone_number CHARACTER VARYING (20),
hire_date DATE NOT NULL,
job_id INTEGER NOT NULL,
salary NUMERIC (8, 2) NOT NULL,
manager_id INTEGER,
department_id INTEGER,
FOREIGN KEY (job_id) REFERENCES jobs (job_id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (department_id) REFERENCES departments (department_id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (manager_id) REFERENCES employees (employee_id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS dependents (
dependent_id SERIAL PRIMARY KEY,
first_name CHARACTER VARYING (50) NOT NULL,
last_name CHARACTER VARYING (50) NOT NULL,
relationship CHARACTER VARYING (25) NOT NULL,
employee_id INTEGER NOT NULL,
FOREIGN KEY (employee_id) REFERENCES employees (employee_id) ON DELETE CASCADE ON UPDATE CASCADE
);


/*Data for the table regions */

INSERT INTO regions(region_id,region_name) VALUES (1,'Europe');
INSERT INTO regions(region_id,region_name) VALUES (2,'Americas');
Expand Down Expand Up @@ -162,19 +221,19 @@ INSERT INTO dependents(dependent_id,first_name,last_name,relationship,employee_i
INSERT INTO dependents(dependent_id,first_name,last_name,relationship,employee_id) VALUES (30,'Sandra','Taylor','Child',176);

-- break foreign key constraints
ALTER TABLE fk_violations.countries
ALTER TABLE countries
DISABLE TRIGGER ALL;

UPDATE fk_violations.countries SET region_id = 6 WHERE country_id IN ('US');
UPDATE countries SET region_id = 6 WHERE country_id IN ('US');

ALTER TABLE fk_violations.countries
ALTER TABLE countries
ENABLE TRIGGER ALL;


ALTER TABLE fk_violations.dependents
ALTER TABLE dependents
DISABLE TRIGGER ALL;

UPDATE fk_violations.dependents SET employee_id = 1000 WHERE last_name IN ('King', 'Colmenares');
UPDATE dependents SET employee_id = 1000 WHERE last_name IN ('King', 'Colmenares');

ALTER TABLE fk_violations.dependents
ALTER TABLE dependents
ENABLE TRIGGER ALL;
Loading

0 comments on commit d109f85

Please sign in to comment.