Skip to content

Commit

Permalink
including IF NOT EXISTS to all CREATE TABLE commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lmassaoy committed Feb 14, 2025
1 parent f6c3bc0 commit 0a074b6
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE lineage_events (
CREATE TABLE IF NOT EXISTS lineage_events (
event_time timestamp with time zone,
event jsonb,
event_type text,
Expand Down
28 changes: 14 additions & 14 deletions api/src/main/resources/marquez/db/migration/V1__initial_schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE namespaces (
CREATE TABLE IF NOT EXISTS namespaces (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
Expand All @@ -9,13 +9,13 @@ CREATE TABLE namespaces (
current_owner_name VARCHAR(64)
);

CREATE TABLE owners (
CREATE TABLE IF NOT EXISTS owners (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
name VARCHAR(64) UNIQUE NOT NULL
);

CREATE TABLE namespace_ownerships (
CREATE TABLE IF NOT EXISTS namespace_ownerships (
uuid UUID PRIMARY KEY,
started_at TIMESTAMP NOT NULL,
ended_at TIMESTAMP,
Expand All @@ -24,7 +24,7 @@ CREATE TABLE namespace_ownerships (
UNIQUE (namespace_uuid, owner_uuid)
);

CREATE TABLE sources (
CREATE TABLE IF NOT EXISTS sources (
uuid UUID PRIMARY KEY,
type VARCHAR(64) NOT NULL,
created_at TIMESTAMP NOT NULL,
Expand All @@ -35,7 +35,7 @@ CREATE TABLE sources (
UNIQUE (name, connection_url)
);

CREATE TABLE datasets (
CREATE TABLE IF NOT EXISTS datasets (
uuid UUID PRIMARY KEY,
type VARCHAR(64) NOT NULL,
created_at TIMESTAMP NOT NULL,
Expand All @@ -49,7 +49,7 @@ CREATE TABLE datasets (
UNIQUE (namespace_uuid, source_uuid, name, physical_name)
);

CREATE TABLE jobs (
CREATE TABLE IF NOT EXISTS jobs (
uuid UUID PRIMARY KEY,
type VARCHAR(64) NOT NULL,
created_at TIMESTAMP NOT NULL,
Expand All @@ -61,7 +61,7 @@ CREATE TABLE jobs (
UNIQUE (namespace_uuid, name)
);

CREATE TABLE job_versions (
CREATE TABLE IF NOT EXISTS job_versions (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
Expand All @@ -72,21 +72,21 @@ CREATE TABLE job_versions (
UNIQUE (job_uuid, version)
);

CREATE TABLE job_versions_io_mapping (
CREATE TABLE IF NOT EXISTS job_versions_io_mapping (
job_version_uuid UUID REFERENCES job_versions(uuid),
dataset_uuid UUID REFERENCES datasets(uuid),
io_type VARCHAR(64) NOT NULL,
PRIMARY KEY (job_version_uuid, dataset_uuid, io_type)
);

CREATE TABLE run_args (
CREATE TABLE IF NOT EXISTS run_args (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
args VARCHAR(255) NOT NULL,
checksum VARCHAR(255) UNIQUE NOT NULL
);

CREATE TABLE runs (
CREATE TABLE IF NOT EXISTS runs (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
Expand All @@ -97,14 +97,14 @@ CREATE TABLE runs (
current_run_state VARCHAR(64)
);

CREATE TABLE run_states (
CREATE TABLE IF NOT EXISTS run_states (
uuid UUID PRIMARY KEY,
transitioned_at TIMESTAMP NOT NULL,
run_uuid UUID REFERENCES runs(uuid),
state VARCHAR(64) NOT NULL
);

CREATE TABLE dataset_versions (
CREATE TABLE IF NOT EXISTS dataset_versions (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
dataset_uuid UUID REFERENCES datasets(uuid),
Expand All @@ -113,12 +113,12 @@ CREATE TABLE dataset_versions (
UNIQUE (dataset_uuid, version)
);

CREATE TABLE stream_versions (
CREATE TABLE IF NOT EXISTS stream_versions (
dataset_version_uuid UUID REFERENCES dataset_versions(uuid),
schema_location VARCHAR(255) UNIQUE NOT NULL
);

CREATE TABLE runs_input_mapping (
CREATE TABLE IF NOT EXISTS runs_input_mapping (
run_uuid UUID REFERENCES runs(uuid),
dataset_version_uuid UUID REFERENCES dataset_versions(uuid),
PRIMARY KEY (run_uuid, dataset_version_uuid)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE job_contexts (
CREATE TABLE IF NOT EXISTS job_contexts (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
context TEXT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

create table job_versions_io_mapping_inputs as select * from job_versions_io_mapping where io_type = 'INPUT';
create table job_versions_io_mapping_outputs as select * from job_versions_io_mapping where io_type = 'OUTPUT';
CREATE TABLE IF NOT EXISTS job_versions_io_mapping_inputs as select * from job_versions_io_mapping where io_type = 'INPUT';
CREATE TABLE IF NOT EXISTS job_versions_io_mapping_outputs as select * from job_versions_io_mapping where io_type = 'OUTPUT';
alter table job_versions_io_mapping_inputs add column job_uuid uuid;
alter table job_versions_io_mapping_outputs add column job_uuid uuid;
update job_versions_io_mapping_outputs set job_uuid = j.job_uuid from job_versions j where job_version_uuid = j.uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE UNIQUE INDEX unique_jobs_namespace_uuid_name_parent ON jobs (name, namesp
ALTER TABLE jobs
ADD CONSTRAINT unique_jobs_namespace_uuid_name_parent UNIQUE USING INDEX unique_jobs_namespace_uuid_name_parent;

CREATE TABlE jobs_fqn
CREATE TABLE IF NOT EXISTS jobs_fqn
(
uuid uuid NOT NULL PRIMARY KEY,
namespace_uuid uuid NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE dataset_symlinks (
CREATE TABLE IF NOT EXISTS dataset_symlinks (
dataset_uuid UUID,
name VARCHAR NOT NULL,
namespace_uuid UUID REFERENCES namespaces(uuid),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE column_lineage (
CREATE TABLE IF NOT EXISTS column_lineage (
output_dataset_version_uuid uuid REFERENCES dataset_versions(uuid), -- allows join to run_id
output_dataset_field_uuid uuid REFERENCES dataset_fields(uuid),
input_dataset_version_uuid uuid REFERENCES dataset_versions(uuid), -- speed up graph column lineage graph traversal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE dataset_fields (
CREATE TABLE IF NOT EXISTS dataset_fields (
uuid UUID PRIMARY KEY,
type VARCHAR(64) NOT NULL,
created_at TIMESTAMP NOT NULL,
Expand All @@ -11,7 +11,7 @@ CREATE TABLE dataset_fields (
UNIQUE (dataset_uuid, name)
);

CREATE TABLE dataset_versions_field_mapping (
CREATE TABLE IF NOT EXISTS dataset_versions_field_mapping (
dataset_version_uuid UUID REFERENCES dataset_versions(uuid),
dataset_field_uuid UUID REFERENCES dataset_fields(uuid),
PRIMARY KEY (dataset_version_uuid, dataset_field_uuid)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE dataset_facets (
CREATE TABLE IF NOT EXISTS dataset_facets (
created_at TIMESTAMPTZ NOT NULL,
dataset_uuid UUID REFERENCES datasets(uuid),
dataset_version_uuid UUID REFERENCES dataset_versions(uuid),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE job_facets (
CREATE TABLE IF NOT EXISTS job_facets (
created_at TIMESTAMPTZ NOT NULL,
job_uuid UUID REFERENCES jobs(uuid),
run_uuid UUID REFERENCES runs(uuid),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE run_facets (
CREATE TABLE IF NOT EXISTS run_facets (
created_at TIMESTAMPTZ NOT NULL,
run_uuid UUID REFERENCES runs(uuid),
lineage_event_time TIMESTAMPTZ NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE facet_migration_lock (
CREATE TABLE IF NOT EXISTS facet_migration_lock (
created_at TIMESTAMPTZ,
run_uuid UUID
);
6 changes: 3 additions & 3 deletions api/src/main/resources/marquez/db/migration/V5__add_tags.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* SPDX-License-Identifier: Apache-2.0 */

CREATE TABLE tags (
CREATE TABLE IF NOT EXISTS tags (
uuid UUID PRIMARY KEY,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
name VARCHAR(255) NOT NULL UNIQUE,
description TEXT
);

CREATE TABLE datasets_tag_mapping (
CREATE TABLE IF NOT EXISTS datasets_tag_mapping (
dataset_uuid UUID REFERENCES datasets(uuid),
tag_uuid UUID REFERENCES tags(uuid),
tagged_at TIMESTAMP NOT NULL,
PRIMARY KEY (tag_uuid, dataset_uuid)
);

CREATE TABLE dataset_fields_tag_mapping (
CREATE TABLE IF NOT EXISTS dataset_fields_tag_mapping (
dataset_field_uuid UUID REFERENCES dataset_fields(uuid),
tag_uuid UUID REFERENCES tags(uuid),
tagged_at TIMESTAMP NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
CREATE TABLE jobs_tag_mapping (
CREATE TABLE IF NOT EXISTS jobs_tag_mapping (
job_uuid UUID REFERENCES jobs(uuid),
tag_uuid UUID REFERENCES tags(uuid),
tagged_at TIMESTAMPTZ NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
CREATE TABLE dataset_schema_versions(
CREATE TABLE IF NOT EXISTS dataset_schema_versions(
uuid UUID PRIMARY KEY,
dataset_uuid UUID REFERENCES datasets(uuid) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: Apache-2.0 */
CREATE TABLE dataset_schema_versions_field_mapping(
CREATE TABLE IF NOT EXISTS dataset_schema_versions_field_mapping(
dataset_schema_version_uuid UUID REFERENCES dataset_schema_versions(uuid) ON DELETE CASCADE,
dataset_field_uuid UUID REFERENCES dataset_fields(uuid) ON DELETE CASCADE,
PRIMARY KEY (dataset_schema_version_uuid, dataset_field_uuid)
Expand Down

0 comments on commit 0a074b6

Please sign in to comment.