From 43d5779d5f66714a55ef2f3ddc50485f177ed510 Mon Sep 17 00:00:00 2001 From: Claudio Barril Date: Wed, 29 Jan 2014 22:15:26 -0300 Subject: [PATCH] deleting user id field and adding collaborator foreing key from access --- config/database/hsql/create-schemas.sql | 8 +++++--- config/database/mysql/create-schemas.sql | 8 +++++--- config/database/mysql/v3.0-to-v3.2.sql | 7 +++++++ config/database/postgres/create-schemas.sql | 6 +++--- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 config/database/mysql/v3.0-to-v3.2.sql diff --git a/config/database/hsql/create-schemas.sql b/config/database/hsql/create-schemas.sql index 69bf4c0e..8a4297b3 100644 --- a/config/database/hsql/create-schemas.sql +++ b/config/database/hsql/create-schemas.sql @@ -4,8 +4,7 @@ CREATE TABLE COLLABORATOR ( creation_date DATE); CREATE TABLE USER ( - id INTEGER NOT NULL IDENTITY, - colaborator_id INTEGER NOT NULL, + colaborator_id INTEGER NOT NULL IDENTITY, authentication_type CHAR(1) NOT NULL, authenticator_uri VARCHAR(255) NULL, firstname VARCHAR(255) NOT NULL, @@ -68,7 +67,10 @@ CREATE TABLE TAG CREATE TABLE ACCESS_AUDITORY ( id INTEGER NOT NULL IDENTITY, user_id INTEGER NOT NULL, - login_date DATE + login_date DATE, + FOREIGN KEY (user_id) REFERENCES USER (colaborator_id) + ON DELETE CASCADE + ON UPDATE NO ACTION ); COMMIT; diff --git a/config/database/mysql/create-schemas.sql b/config/database/mysql/create-schemas.sql index c9164ad0..8831d086 100644 --- a/config/database/mysql/create-schemas.sql +++ b/config/database/mysql/create-schemas.sql @@ -13,8 +13,7 @@ CREATE TABLE COLLABORATOR ( CHARACTER SET utf8; CREATE TABLE USER ( - id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - colaborator_id INTEGER NOT NULL, + colaborator_id INTEGER NOT NULL PRIMARY KEY, authentication_type CHAR(1) CHARACTER SET utf8 NOT NULL, authenticator_uri VARCHAR(255) @@ -103,7 +102,10 @@ CREATE TABLE TAG ( CREATE TABLE ACCESS_AUDITORY ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, login_date DATE, - user_id INTEGER NOT NULL + user_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES USER (colaborator_id) + ON DELETE CASCADE + ON UPDATE NO ACTION ) CHARACTER SET utf8; diff --git a/config/database/mysql/v3.0-to-v3.2.sql b/config/database/mysql/v3.0-to-v3.2.sql new file mode 100644 index 00000000..c3570244 --- /dev/null +++ b/config/database/mysql/v3.0-to-v3.2.sql @@ -0,0 +1,7 @@ +ALTER TABLE `USER` DROP COLUMN `id`; + +ALTER TABLE `ACCESS_AUDITORY` + ADD CONSTRAINT + FOREIGN KEY (user_id) REFERENCES USER (colaborator_id) + ON DELETE CASCADE + ON UPDATE NO ACTION; \ No newline at end of file diff --git a/config/database/postgres/create-schemas.sql b/config/database/postgres/create-schemas.sql index 723cc2dd..544f11f3 100644 --- a/config/database/postgres/create-schemas.sql +++ b/config/database/postgres/create-schemas.sql @@ -5,10 +5,9 @@ CREATE TABLE COLLABORATOR ( ); CREATE TABLE "user" ( - id SERIAL NOT NULL PRIMARY KEY, authentication_type TEXT NOT NULL, authenticator_uri VARCHAR(255), - colaborator_id INTEGER NOT NULL, + colaborator_id INTEGER NOT NULL PRIMARY KEY, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, @@ -73,7 +72,8 @@ CREATE TABLE TAG ( CREATE TABLE ACCESS_AUDITORY ( id SERIAL NOT NULL PRIMARY KEY, login_date DATE, - user_id INTEGER NOT NULL + user_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES "user" (colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION );