Skip to content

Commit

Permalink
Migration scripts for closure.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 16, 2014
1 parent 6fe2f55 commit a52341d
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
24 changes: 24 additions & 0 deletions config/sql/midpoint/3.0/h2/h2-3.0-closure-upgrade.sql
@@ -0,0 +1,24 @@
DROP TABLE m_org_closure;

DROP TABLE IF EXISTS m_org_incorrect;

CREATE TABLE m_org_closure (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
val INTEGER NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
REFERENCES m_object;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_descendant
FOREIGN KEY (descendant_oid)
REFERENCES m_object;
33 changes: 33 additions & 0 deletions config/sql/midpoint/3.0/mysql/mysql-3.0-closure-upgrade.sql
@@ -0,0 +1,33 @@
DROP TABLE m_org_closure;

drop table if exists m_org_incorrect;

--
-- Note: if getting
-- "[HY000][150] Create table 'midpoint/#sql-7ec_8' with foreign key constraint failed.
-- There is no index in the referenced table where the referenced columns appear as the first columns."
-- then check the character set/collation compatibility between ancestor_oid/descendant_oid and m_object(oid).
-- E.g. try to remove "DEFAULT CHARACTER SET utf8 COLLATE utf8_bin" from definition; or add the same to m_object.
--

CREATE TABLE m_org_closure (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL ,
val INTEGER NOT NULL ,
PRIMARY KEY (descendant_oid, ancestor_oid)
)
DEFAULT CHARACTER SET utf8
COLLATE utf8_bin
ENGINE =InnoDB;

ALTER TABLE m_org_closure
ADD INDEX fk_ancestor (ancestor_oid),
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
REFERENCES m_object (oid);

ALTER TABLE m_org_closure
ADD INDEX fk_descendant (descendant_oid),
ADD CONSTRAINT fk_descendant
FOREIGN KEY (descendant_oid)
REFERENCES m_object (oid);
48 changes: 48 additions & 0 deletions config/sql/midpoint/3.0/oracle/oracle-3.0-closure-upgrade.sql
@@ -0,0 +1,48 @@
DROP TABLE m_org_closure;

BEGIN
EXECUTE IMMEDIATE 'DROP TABLE m_org_incorrect';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;

CREATE TABLE m_org_closure (
descendant_oid VARCHAR2(36 CHAR) NOT NULL,
ancestor_oid VARCHAR2(36 CHAR) NOT NULL,
val NUMBER(10, 0) NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
) INITRANS 30;

BEGIN
EXECUTE IMMEDIATE 'DROP TABLE m_org_closure_temp_delta';
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE != -942 THEN
RAISE;
END IF;
END;

CREATE GLOBAL TEMPORARY TABLE m_org_closure_temp_delta (
descendant_oid VARCHAR2(36 CHAR) NOT NULL,
ancestor_oid VARCHAR2(36 CHAR) NOT NULL,
val NUMBER (10, 0) NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
) ON COMMIT DELETE ROWS;

CREATE INDEX iAncestor ON m_org_closure (ancestor_oid) INITRANS 30;

CREATE INDEX iDescendant ON m_org_closure (descendant_oid) INITRANS 30;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
REFERENCES m_object;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_descendant
FOREIGN KEY (descendant_oid)
REFERENCES m_object;

@@ -0,0 +1,24 @@
DROP TABLE m_org_closure;

DROP TABLE IF EXISTS m_org_incorrect;

CREATE TABLE m_org_closure (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
val INT4 NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
REFERENCES m_object;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_descendant
FOREIGN KEY (descendant_oid)
REFERENCES m_object;
@@ -0,0 +1,25 @@
DROP TABLE m_org_closure;

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'm_org_incorrect')
DROP TABLE m_org_incorrect;

CREATE TABLE m_org_closure (
descendant_oid NVARCHAR(36) COLLATE database_default NOT NULL,
ancestor_oid NVARCHAR(36) COLLATE database_default NOT NULL,
val INT NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
REFERENCES m_object;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_descendant
FOREIGN KEY (descendant_oid)
REFERENCES m_object;

0 comments on commit a52341d

Please sign in to comment.