All Downloads are FREE. Search and download functionalities are using the official Maven repository.

db.migration.V0.5.2__init.sql Maven / Gradle / Ivy

alter table user_clients add column permissions varchar(255) DEFAULT 'PERM_CAN_VIEW';

update user_clients set permissions='PERM_OWNER' where user_id in (select user_id from users where role='ROLE_ADMIN');

CREATE TABLE public.system_properties ( 
    key				varchar(255) PRIMARY KEY NOT NULL,
    value			varchar(255) NOT NULL
)
WITHOUT OIDS 
TABLESPACE pg_default;

insert into system_properties (key, value) values('version','0.5.2');

CREATE TABLE public.folders ( 
    folder_id		UUID PRIMARY KEY,
    name			varchar(255) NOT NULL,
    inserted_date	timestamp NOT NULL
)
WITHOUT OIDS 
TABLESPACE pg_default;

CREATE TABLE public.folders_access ( 
    folder_access_id	UUID PRIMARY KEY,
    folder_id 			UUID NOT NULL,
    user_id 			varchar(255) NOT NULL,
    permissions			varchar(255) NOT NULL,
    inserted_date		timestamp NOT NULL
)
WITHOUT OIDS 
TABLESPACE pg_default;

CREATE INDEX folders_access_user_id_idx ON public.folders_access (user_id);

CREATE TABLE public.folder_logs ( 
    folder_log_id	SERIAL PRIMARY KEY,
    folder_id		UUID NOT NULL,
    uuid			varchar(255) NOT NULL,
    type			varchar(25) NOT NULL,
    synctype		varchar(25) NOT NULL,
    inserted_date	timestamp NOT NULL
)
WITHOUT OIDS 
TABLESPACE pg_default;

CREATE INDEX folder_logs_folder_id_idx ON public.folder_logs (folder_id);

---
--- folder_forms
---
CREATE TABLE public.folder_forms  ( 
    folder_form_id	UUID PRIMARY KEY,
    folder_id		UUID NOT NULL,
    parent_uuid		varchar(255) NULL,
    uuid			varchar(255) NOT NULL,
    type 			varchar(25) NOT NULL,
    sha1_hash		varchar(255) NOT NULL,
	asset_id		varchar(255) NOT NULL,
	data			JSONB NOT NULL,
    inserted_date	timestamp NOT NULL,
    updated_date	timestamp NOT NULL
)
WITHOUT OIDS 
TABLESPACE pg_default;

CREATE INDEX folder_forms_folderid_idx ON public.folder_forms (folder_id, uuid);

-- insert into folders
insert into folders(folder_id, name, inserted_date) select uuid_in(md5(random()::text || now()::text)::cstring), client_id,now() from oauth_client_details;

-- insert into folder_forms
insert into folder_forms(folder_form_id, folder_id, parent_uuid, uuid, type, sha1_hash, asset_id, data, inserted_date, updated_date)
select uuid_in(md5(random()::text || now()::text)::cstring),
f.folder_id, cf.parent_uuid, cf.uuid, cf.type, cf.sha1_hash, cf.asset_id, cf.data, cf.inserted_date, cf.updated_date 
from client_forms cf join folders f on 1=1;

-- insert into folder_access
insert into folders_access(folder_access_id, folder_id, user_id, permissions, inserted_date)
select uuid_in(md5(random()::text || now()::text)::cstring), f.folder_id, uc.user_id, uc.permissions, uc.inserted_date from user_clients uc join folders f on 1=1;

-- insert into folder_logs
insert into folder_logs(folder_log_id, folder_id, uuid, type, synctype, inserted_date)
select l.log_id, f.folder_id, l.uuid, l.type, l.synctype, l.inserted_date from 
client_form_logs l join folders f on 1=1;


-- update field to uuid
ALTER TABLE assets ALTER COLUMN asset_id TYPE uuid USING asset_id::uuid;
ALTER TABLE folder_forms ALTER COLUMN asset_id TYPE uuid USING asset_id::uuid;
ALTER TABLE users ALTER COLUMN user_id TYPE uuid USING user_id::uuid;
ALTER TABLE user_clients ALTER COLUMN user_id TYPE uuid USING user_id::uuid;
ALTER TABLE folders_access ALTER COLUMN user_id TYPE uuid USING user_id::uuid;
ALTER TABLE folder_forms ALTER COLUMN parent_uuid TYPE uuid USING parent_uuid::uuid;
ALTER TABLE folder_forms ALTER COLUMN uuid TYPE uuid USING uuid::uuid;
ALTER TABLE folder_logs ALTER COLUMN uuid TYPE uuid USING uuid::uuid;

--drop table user_clients;
--drop table client_forms;
--drop table client_form_logs;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy