Skip to content

Commit

Permalink
Updating events and gitspaces tables (#2115)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv-harness authored and Harness committed Jun 17, 2024
1 parent d903c0f commit b36b231
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DROP INDEX gitspace_events_entity_id;
ALTER TABLE gitspace_events DROP COLUMN geven_entity_type;
ALTER TABLE gitspace_events DROP COLUMN geven_entity_uid;
ALTER TABLE gitspace_events DROP COLUMN geven_entity_id;
ALTER TABLE gitspace_events
ADD COLUMN geven_gitspace_config_id INTEGER NOT NULL;
ALTER TABLE gitspace_events
ADD CONSTRAINT fk_geven_gitspace_config_id FOREIGN KEY (geven_gitspace_config_id)
REFERENCES gitspace_configs (gconf_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE;

ALTER TABLE gitspaces
ADD COLUMN gits_infra_provisioned_id INTEGER;
ALTER TABLE gitspaces
ADD CONSTRAINT fk_gits_infra_provisioned_id FOREIGN KEY (gits_infra_provisioned_id)
REFERENCES infra_provisioned (iprov_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION;
DROP index gitspaces_uid_space_id;
ALTER TABLE gitspaces DROP COLUMN gits_uid;
CREATE UNIQUE INDEX gitspaces_gitspace_config_id_space_id ON gitspaces (gits_gitspace_config_id, gits_space_id);

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ALTER TABLE gitspace_events DROP CONSTRAINT fk_geven_gitspace_config_id;
ALTER TABLE gitspace_events DROP COLUMN geven_gitspace_config_id;
ALTER TABLE gitspace_events
ADD COLUMN geven_entity_type TEXT NOT NULL;
ALTER TABLE gitspace_events
ADD COLUMN geven_entity_uid TEXT;
ALTER TABLE gitspace_events
ADD COLUMN geven_entity_id INTEGER NOT NULL;
CREATE INDEX gitspace_events_entity_id ON gitspace_events (geven_entity_id);

ALTER TABLE gitspaces DROP CONSTRAINT fk_gits_infra_provisioned_id;
ALTER TABLE gitspaces DROP COLUMN gits_infra_provisioned_id;
DROP INDEX gitspaces_gitspace_config_id_space_id;
ALTER TABLE gitspaces
ADD COLUMN gits_uid TEXT NOT NULL;
CREATE UNIQUE INDEX gitspaces_uid_space_id ON gitspaces (gits_uid, gits_space_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
CREATE TABLE gitspace_events_temp
(
geven_id INTEGER PRIMARY KEY AUTOINCREMENT,
geven_gitspace_config_id INTEGER NOT NULL,
geven_event TEXT NOT NULL,
geven_created BIGINT NOT NULL,
CONSTRAINT fk_geven_gitspace_config_id FOREIGN KEY (geven_gitspace_config_id)
REFERENCES gitspace_configs (gconf_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);
INSERT INTO gitspace_events_temp (geven_gitspace_config_id, geven_event, geven_created)
SELECT geven_entity_id, geven_event, geven_created
FROM gitspace_events;
DROP INDEX gitspace_events_entity_id;
DROP TABLE gitspace_events;
ALTER TABLE gitspace_events_temp
RENAME TO gitspace_events;



CREATE TABLE gitspaces_temp
(
gits_id INTEGER PRIMARY KEY AUTOINCREMENT,
gits_gitspace_config_id INTEGER NOT NULL,
gits_url TEXT,
gits_state TEXT NOT NULL,
gits_user_uid TEXT NOT NULL,
gits_resource_usage TEXT,
gits_space_id INTEGER NOT NULL,
gits_created BIGINT NOT NULL,
gits_updated BIGINT NOT NULL,
gits_last_used BIGINT NOT NULL,
gits_total_time_used BIGINT NOT NULL,
gits_infra_provisioned_id INTEGER,
gits_tracked_changes TEXT,
gits_access_key TEXT,
gits_access_type TEXT,
gits_machine_user TEXT,
CONSTRAINT fk_gits_gitspace_config_id FOREIGN KEY (gits_gitspace_config_id)
REFERENCES gitspace_configs (gconf_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE RESTRICT,
CONSTRAINT fk_gits_infra_provisioned_id FOREIGN KEY (gits_infra_provisioned_id)
REFERENCES infra_provisioned (iprov_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fk_gits_space_id FOREIGN KEY (gits_space_id)
REFERENCES spaces (space_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);

INSERT INTO gitspaces_temp (gits_gitspace_config_id, gits_url, gits_state, gits_user_uid, gits_resource_usage,
gits_space_id, gits_created, gits_updated, gits_last_used, gits_total_time_used,
gits_tracked_changes, gits_access_key, gits_access_type,
gits_machine_user)
SELECT gits_gitspace_config_id,
gits_url,
gits_state,
gits_user_uid,
gits_resource_usage,
gits_space_id,
gits_created,
gits_updated,
gits_last_used,
gits_total_time_used,
gits_tracked_changes,
gits_access_key,
gits_access_type,
gits_machine_user
FROM gitspaces;

DROP INDEX gitspaces_uid_space_id;
DROP TABLE gitspaces;

ALTER TABLE gitspaces_temp
RENAME TO gitspaces;

CREATE UNIQUE INDEX gitspaces_gitspace_config_id_space_id ON gitspaces (gits_gitspace_config_id, gits_space_id);

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
CREATE TABLE gitspace_events_temp
(
geven_id INTEGER PRIMARY KEY AUTOINCREMENT,
geven_event TEXT NOT NULL,
geven_created BIGINT NOT NULL,
geven_entity_type TEXT NOT NULL,
geven_entity_uid TEXT,
geven_entity_id INTEGER NOT NULL
);

INSERT INTO gitspace_events_temp (geven_event, geven_created, geven_entity_type, geven_entity_id)
SELECT geven_event, geven_created, 'gitspaceConfig' AS geven_entity_type, geven_gitspace_config_id
FROM gitspace_events;

DROP TABLE gitspace_events;

ALTER TABLE gitspace_events_temp
RENAME TO gitspace_events;

CREATE INDEX gitspace_events_entity_id ON gitspace_events (geven_entity_id);

CREATE TABLE gitspaces_temp
(
gits_id INTEGER PRIMARY KEY AUTOINCREMENT,
gits_gitspace_config_id INTEGER NOT NULL,
gits_url TEXT,
gits_state TEXT NOT NULL,
gits_user_uid TEXT NOT NULL,
gits_resource_usage TEXT,
gits_space_id INTEGER NOT NULL,
gits_created BIGINT NOT NULL,
gits_updated BIGINT NOT NULL,
gits_last_used BIGINT NOT NULL,
gits_total_time_used BIGINT NOT NULL,
gits_tracked_changes TEXT,
gits_access_key TEXT,
gits_access_type TEXT,
gits_machine_user TEXT,
gits_uid TEXT NOT NULL,
CONSTRAINT fk_gits_gitspace_config_id FOREIGN KEY (gits_gitspace_config_id)
REFERENCES gitspace_configs (gconf_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE RESTRICT,
CONSTRAINT fk_gits_space_id FOREIGN KEY (gits_space_id)
REFERENCES spaces (space_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);

INSERT INTO gitspaces_temp (gits_gitspace_config_id, gits_url, gits_state, gits_user_uid, gits_resource_usage,
gits_space_id, gits_created, gits_updated, gits_last_used, gits_total_time_used,
gits_tracked_changes, gits_access_key, gits_access_type,
gits_machine_user, gits_uid)
SELECT g.gits_gitspace_config_id,
g.gits_url,
g.gits_state,
g.gits_user_uid,
g.gits_resource_usage,
g.gits_space_id,
g.gits_created,
g.gits_updated,
g.gits_last_used,
g.gits_total_time_used,
g.gits_tracked_changes,
g.gits_access_key,
g.gits_access_type,
g.gits_machine_user,
gconf.gconf_uid AS gits_uid
FROM gitspaces g
JOIN gitspace_configs gconf ON g.gits_gitspace_config_id = gconf.gconf_id;

DROP INDEX gitspaces_gitspace_config_id_space_id;
DROP TABLE gitspaces;

ALTER TABLE gitspaces_temp
RENAME TO gitspaces;

CREATE UNIQUE INDEX gitspaces_uid_space_id ON gitspaces (gits_uid, gits_space_id);

0 comments on commit b36b231

Please sign in to comment.