From 6de32a2a04d61135419126ee0452279df282ac0a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 21 Oct 2020 10:29:13 +0500 Subject: [PATCH] Create table `employee_contacts` --- .../2020-10-21-044318_create_employees/down.sql | 2 ++ migrations/2020-10-21-044318_create_employees/up.sql | 12 ++++++++++++ src/schema.rs | 12 ++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/migrations/2020-10-21-044318_create_employees/down.sql b/migrations/2020-10-21-044318_create_employees/down.sql index 48c016f..6cc5af8 100644 --- a/migrations/2020-10-21-044318_create_employees/down.sql +++ b/migrations/2020-10-21-044318_create_employees/down.sql @@ -1,6 +1,8 @@ -- This file should undo anything in `up.sql` +DROP INDEX index_employee_contacts_on_employee_id; DROP INDEX index_employee_infos_on_employee_id_and_locale; +DROP TABLE employee_contacts; DROP TABLE employee_infos; DROP TABLE employees; diff --git a/migrations/2020-10-21-044318_create_employees/up.sql b/migrations/2020-10-21-044318_create_employees/up.sql index 27bd055..b4fc849 100644 --- a/migrations/2020-10-21-044318_create_employees/up.sql +++ b/migrations/2020-10-21-044318_create_employees/up.sql @@ -16,5 +16,17 @@ CREATE TABLE employee_infos ( CONSTRAINT employee_id_fk FOREIGN KEY (employee_id) REFERENCES employees(id) ); +CREATE TABLE employee_contacts ( + id SERIAL PRIMARY KEY, + employee_id SERIAL NOT NULL, + name VARCHAR NOT NULL, + link VARCHAR NOT NULL, + + CONSTRAINT employee_id_fk FOREIGN KEY (employee_id) REFERENCES employees(id) +); + CREATE UNIQUE INDEX index_employee_infos_on_employee_id_and_locale ON employee_infos USING btree (employee_id, locale); + +CREATE UNIQUE INDEX index_employee_contacts_on_employee_id + ON employee_contacts USING btree (employee_id); diff --git a/src/schema.rs b/src/schema.rs index 4189ca7..c16ce32 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,3 +1,12 @@ +table! { + employee_contacts (id) { + id -> Int4, + employee_id -> Int4, + name -> Varchar, + link -> Varchar, + } +} + table! { employee_infos (id) { id -> Int4, @@ -24,9 +33,8 @@ table! { } } -joinable!(employee_infos -> employees (employee_id)); - allow_tables_to_appear_in_same_query!( + employee_contacts, employee_infos, employees, users,