Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Reset DB schema migrations (not technically made a release yet...this will mean a clean install for any existing deployments which was agreed as acceptable)

Rich Turnerb0abce77ae1f
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20180720_02__NotificationChanges.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20180720_02__NotificationChanges.sql
deleted file mode 100644
index b1ec3e03e..000000000
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20180720_02__NotificationChanges.sql
+++ /dev/null
@@ -1,24 +0,0 @@
-
-/*
- New notification infrastructure, rather than migrate existing notifications the entire table is dropped and recreated
- */
-
-drop table ALERT_NOTIFICATION cascade;
-drop table DEVICE_NOTIFICATION_TOKEN cascade;
-
-create table NOTIFICATION (
- ID int8 not null,
- NAME varchar(255),
- TYPE varchar(50) not null,
- TARGET varchar(50) not null,
- TARGET_ID varchar(43) not null,
- SOURCE varchar(50) not null,
- SOURCE_ID varchar(43),
- MESSAGE jsonb,
- ERROR varchar(255),
- SENT_ON timestamp with time zone not null,
- DELIVERED_ON timestamp with time zone,
- ACKNOWLEDGED_ON timestamp with time zone,
- ACKNOWLEDGEMENT varchar(255),
- primary key (ID)
-);
\ No newline at end of file
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql
deleted file mode 100644
index 0005a2bed..000000000
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql
+++ /dev/null
@@ -1,67 +0,0 @@
-
-/*
- Removed use of REALM_ID and now just using REALM
- */
-
--- UPDATE ASSET TABLE
-
-ALTER TABLE ASSET
- DROP CONSTRAINT asset_realm_id_fkey,
- ADD COLUMN REALM VARCHAR(255);
-
-DO $$
- begin
- IF EXISTS(SELECT to_regclass('public.realm')) THEN
- UPDATE openremote.ASSET A SET REALM = R.NAME FROM public.REALM R WHERE A.REALM_ID = R.id;
- END IF;
- end
- $$;
-
-ALTER TABLE ASSET
- ALTER COLUMN REALM SET NOT NULL,
- add foreign key (REALM) references PUBLIC.REALM (NAME),
- DROP COLUMN REALM_ID;
-
-
--- UPDATE TENANT RULSET TABLE
-
-ALTER TABLE TENANT_RULESET
- DROP CONSTRAINT tenant_ruleset_realm_id_fkey,
- ADD COLUMN REALM VARCHAR(255);
-
-DO $$
- begin
- IF EXISTS(SELECT to_regclass('public.realm')) THEN
- UPDATE openremote.TENANT_RULESET TR SET REALM = R.NAME FROM public.REALM R WHERE TR.REALM_ID = R.id;
- END IF;
- end
- $$;
-
-ALTER TABLE TENANT_RULESET
- ALTER COLUMN REALM SET NOT NULL,
- add foreign key (REALM) references PUBLIC.REALM (NAME),
- DROP COLUMN REALM_ID;
-
-
--- UPDATE USER ASSET TABLE
-
-ALTER TABLE USER_ASSET
- DROP CONSTRAINT user_asset_realm_id_fkey,
- ADD COLUMN REALM VARCHAR(255);
-
-DO $$
- begin
- IF EXISTS(SELECT to_regclass('public.realm')) THEN
- UPDATE openremote.USER_ASSET A SET REALM = R.NAME FROM public.REALM R WHERE A.REALM_ID = R.id;
- END IF;
- end
- $$;
-
-ALTER TABLE USER_ASSET
- ALTER COLUMN REALM SET NOT NULL,
- add foreign key (REALM) references PUBLIC.REALM (NAME) on delete cascade,
- DROP COLUMN REALM_ID;
-
-
--- UPDATE NOTIFICATION TABLE
-UPDATE openremote.notification N SET target_id = R.NAME FROM public.REALM R WHERE target = 'TENANT' and N.target_id = R.id;
\ No newline at end of file
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20190304_04__AddRulesetPublicRead.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20190304_04__AddRulesetPublicRead.sql
deleted file mode 100644
index 73d7dfe4f..000000000
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20190304_04__AddRulesetPublicRead.sql
+++ /dev/null
@@ -1,14 +0,0 @@
-
-/*
- Adds public read flag to rulesets
- */
-
--- UPDATE ASSET_RULESET
-
-ALTER TABLE ASSET_RULESET
- ADD COLUMN ACCESS_PUBLIC_READ boolean not null DEFAULT false;
-
-
--- UPDATE TENANT_RULESET
-ALTER TABLE TENANT_RULESET
- ADD COLUMN ACCESS_PUBLIC_READ boolean not null DEFAULT false;
\ No newline at end of file
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20190708_05__AddRulesetMeta.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20190708_05__AddRulesetMeta.sql
deleted file mode 100644
index f410dbd64..000000000
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20190708_05__AddRulesetMeta.sql
+++ /dev/null
@@ -1,17 +0,0 @@
-
-/*
- Adds meta column to rulesets
- */
-
--- UPDATE GLOBAL_RULESET
-ALTER TABLE GLOBAL_RULESET
- ADD COLUMN META jsonb;
-
--- UPDATE ASSET_RULESET
-ALTER TABLE ASSET_RULESET
- ADD COLUMN META jsonb;
-
-
--- UPDATE TENANT_RULESET
-ALTER TABLE TENANT_RULESET
- ADD COLUMN META jsonb;
\ No newline at end of file
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20180317_01__Schema.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
similarity index 62%
rename from manager/src/main/resources/org/openremote/manager/setup/database/V20180317_01__Schema.sql
rename to manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
index 6ec5b1bc1..d376a67f6 100644
--- a/manager/src/main/resources/org/openremote/manager/setup/database/V20180317_01__Schema.sql
+++ b/manager/src/main/resources/org/openremote/manager/setup/database/V20191202_01__Schema.sql
@@ -21,7 +21,7 @@ create table ASSET (
CREATED_ON timestamp with time zone not null,
NAME varchar(1023) not null,
PARENT_ID varchar(36),
- REALM_ID varchar(255) not null,
+ REALM varchar(255) not null,
ASSET_TYPE varchar(255) not null,
ACCESS_PUBLIC_READ boolean not null,
OBJ_VERSION int8 not null,
@@ -45,43 +45,48 @@ create table GLOBAL_RULESET (
LAST_MODIFIED timestamp with time zone not null,
NAME varchar(255) not null,
RULES text not null,
- RULES_LANG varchar(255) not null default 'GROOVY',
+ RULES_LANG varchar(255) not null,
OBJ_VERSION int8 not null,
+ META jsonb,
primary key (ID)
);
create table ASSET_RULESET (
- ID int8 not null,
- CREATED_ON timestamp with time zone not null,
- ENABLED boolean not null,
- LAST_MODIFIED timestamp with time zone not null,
- NAME varchar(255) not null,
- RULES text not null,
- RULES_LANG varchar(255) not null default 'GROOVY',
- OBJ_VERSION int8 not null,
- ASSET_ID char(22) not null,
+ ID int8 not null,
+ CREATED_ON timestamp with time zone not null,
+ ENABLED boolean not null,
+ LAST_MODIFIED timestamp with time zone not null,
+ NAME varchar(255) not null,
+ RULES text not null,
+ RULES_LANG varchar(255) not null default 'GROOVY',
+ OBJ_VERSION int8 not null,
+ ASSET_ID char(22) not null,
+ ACCESS_PUBLIC_READ boolean not null default false,
+ META jsonb,
primary key (ID)
);
create table TENANT_RULESET (
- ID int8 not null,
- CREATED_ON timestamp with time zone not null,
- ENABLED boolean not null,
- LAST_MODIFIED timestamp with time zone not null,
- NAME varchar(255) not null,
- RULES text not null,
- RULES_LANG varchar(255) not null default 'GROOVY',
- OBJ_VERSION int8 not null,
- REALM_ID varchar(255) not null,
+ ID int8 not null,
+ CREATED_ON timestamp with time zone not null,
+ ENABLED boolean not null,
+ LAST_MODIFIED timestamp with time zone not null,
+ NAME varchar(255) not null,
+ RULES text not null,
+ RULES_LANG varchar(255) not null default 'GROOVY',
+ OBJ_VERSION int8 not null,
+ REALM varchar(255) not null,
+ ACCESS_PUBLIC_READ boolean not null default false,
+ META jsonb,
primary key (ID)
);
create table USER_ASSET (
ASSET_ID char(22) not null,
- REALM_ID varchar(36) not null,
+ REALM varchar(255) not null,
USER_ID varchar(36) not null,
CREATED_ON timestamp with time zone not null,
- primary key (ASSET_ID, REALM_ID, USER_ID)
+ primary key (ASSET_ID, REALM, USER_ID)
);
create table USER_CONFIGURATION (
@@ -90,27 +95,23 @@ create table USER_CONFIGURATION (
primary key (USER_ID)
);
-create table ALERT_NOTIFICATION (
+create table NOTIFICATION (
ID int8 not null,
- ACTIONS jsonb,
- APP_URL varchar(255) not null,
- CREATED_ON timestamp with time zone not null,
- DELIVERY_STATUS varchar(255),
- MESSAGE varchar(255) not null,
- TITLE varchar(255) not null,
- USER_ID varchar(255),
+ NAME varchar(255),
+ TYPE varchar(50) not null,
+ TARGET varchar(50) not null,
+ TARGET_ID varchar(43) not null,
+ SOURCE varchar(50) not null,
+ SOURCE_ID varchar(43),
+ MESSAGE jsonb,
+ ERROR varchar(255),
+ SENT_ON timestamp with time zone not null,
+ DELIVERED_ON timestamp with time zone,
+ ACKNOWLEDGED_ON timestamp with time zone,
+ ACKNOWLEDGEMENT varchar(255),
primary key (ID)
);
-create table DEVICE_NOTIFICATION_TOKEN (
- DEVICE_ID varchar(255) not null,
- USER_ID varchar(36) not null,
- DEVICE_TYPE varchar(255),
- TOKEN varchar(4096) not null,
- UPDATED_ON timestamp with time zone not null,
- primary key (DEVICE_ID, USER_ID)
-);
-
create table SYSLOG_EVENT (
ID int8 not null,
TIMESTAMP int8 not null,
@@ -157,20 +158,17 @@ alter table ASSET
add foreign key (PARENT_ID) references ASSET (ID);
alter table ASSET
- add foreign key (REALM_ID) references PUBLIC.REALM (ID);
+ add foreign key (REALM) references PUBLIC.REALM (NAME);
alter table ASSET_DATAPOINT
add foreign key (ENTITY_ID) references ASSET (ID) on delete cascade;
alter table TENANT_RULESET
- add foreign key (REALM_ID) references PUBLIC.REALM (ID);
+ add foreign key (REALM) references PUBLIC.REALM (NAME);
alter table ASSET_RULESET
add foreign key (ASSET_ID) references ASSET (ID) on delete cascade;
-alter table DEVICE_NOTIFICATION_TOKEN
- add foreign key (USER_ID) references PUBLIC.USER_ENTITY (ID) on delete cascade;
-
alter table USER_CONFIGURATION
add foreign key (USER_ID) references PUBLIC.USER_ENTITY (ID) on delete cascade;
@@ -181,7 +179,7 @@ alter table USER_ASSET
add foreign key (ASSET_ID) references ASSET (ID) on delete cascade;
alter table USER_ASSET
- add foreign key (REALM_ID) references PUBLIC.REALM (ID) on delete cascade;
+ add foreign key (REALM) references PUBLIC.REALM (NAME) on delete cascade;
/*
############################# INDICES #############################