Skip to content

Commit

Permalink
Flatten yugabyte scd migration
Browse files Browse the repository at this point in the history
  • Loading branch information
barroco committed Dec 5, 2024
1 parent 5cd2be1 commit 6ba104f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 172 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- This migration is equivalent to scd v3.2.0 schema for CockroachDB.

CREATE TABLE IF NOT EXISTS scd_subscriptions (
id UUID PRIMARY KEY,
owner TEXT NOT NULL,
Expand All @@ -10,21 +12,16 @@ CREATE TABLE IF NOT EXISTS scd_subscriptions (
starts_at TIMESTAMPTZ,
ends_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ NOT NULL,
cells BIGINT[],
CHECK (starts_at IS NULL OR ends_at IS NULL OR starts_at < ends_at),
CHECK (notify_for_operations OR notify_for_constraints)
);
CREATE INDEX ss_owner_idx ON scd_subscriptions (owner);
CREATE INDEX ss_starts_at_idx ON scd_subscriptions (starts_at);
CREATE INDEX ss_ends_at_idx ON scd_subscriptions (ends_at);
CREATE INDEX ss_cells_idx ON scd_subscriptions USING ybgin (cells);

CREATE TABLE IF NOT EXISTS scd_cells_subscriptions (
cell_id BIGINT NOT NULL,
cell_level INT CHECK (cell_level BETWEEN 0 and 30),
subscription_id UUID NOT NULL REFERENCES scd_subscriptions (id) ON DELETE CASCADE,
PRIMARY KEY (cell_id, subscription_id)
);
CREATE INDEX scs_cell_id_idx ON scd_cells_subscriptions (cell_id);
CREATE INDEX scs_subscription_id_idx ON scd_cells_subscriptions (subscription_id);
CREATE TYPE operational_intent_state AS ENUM ('Unknown', 'Accepted', 'Activated', 'Nonconforming', 'Contingent');

CREATE TABLE IF NOT EXISTS scd_operations (
id UUID PRIMARY KEY,
Expand All @@ -35,9 +32,19 @@ CREATE TABLE IF NOT EXISTS scd_operations (
altitude_upper REAL,
starts_at TIMESTAMPTZ,
ends_at TIMESTAMPTZ,
subscription_id UUID NOT NULL REFERENCES scd_subscriptions(id) ON DELETE CASCADE,
subscription_id UUID REFERENCES scd_subscriptions(id) ON DELETE CASCADE,
updated_at TIMESTAMPTZ NOT NULL,
CHECK (starts_at IS NULL OR ends_at IS NULL OR starts_at < ends_at)
state operational_intent_state NOT NULL DEFAULT 'Unknown',
cells BIGINT[],
uss_requested_ovn TEXT,
past_ovns TEXT[] NOT NULL DEFAULT ARRAY []::TEXT[],
CHECK (starts_at IS NULL OR ends_at IS NULL OR starts_at < ends_at),
CHECK (uss_requested_ovn != ''),
CHECK (
array_position(past_ovns, NULL) IS NULL AND
array_position(past_ovns, '') IS NULL AND
array_position(past_ovns, uss_requested_ovn) IS NULL
)
);
CREATE INDEX so_owner_idx ON scd_operations (owner);
CREATE INDEX so_altitude_lower_idx ON scd_operations (altitude_lower);
Expand All @@ -46,15 +53,7 @@ CREATE INDEX so_starts_at_idx ON scd_operations (starts_at);
CREATE INDEX so_ends_at_idx ON scd_operations (ends_at);
CREATE INDEX so_updated_at_idx ON scd_operations (updated_at);
CREATE INDEX so_subscription_id_idx ON scd_operations (subscription_id);

CREATE TABLE IF NOT EXISTS scd_cells_operations (
cell_id BIGINT NOT NULL,
cell_level INT CHECK (cell_level BETWEEN 0 and 30),
operation_id UUID NOT NULL REFERENCES scd_operations (id) ON DELETE CASCADE,
PRIMARY KEY (cell_id, operation_id)
);
CREATE INDEX sco_cell_id_idx ON scd_cells_operations (cell_id);
CREATE INDEX sco_operation_id_idx ON scd_cells_operations (operation_id);
CREATE INDEX so_cells_idx ON scd_operations USING ybgin (cells);

CREATE TABLE IF NOT EXISTS scd_constraints (
id UUID PRIMARY KEY,
Expand All @@ -74,9 +73,16 @@ CREATE INDEX sc_starts_at_idx ON scd_constraints (starts_at);
CREATE INDEX sc_ends_at_idx ON scd_constraints (ends_at);
CREATE INDEX sc_cells_idx ON scd_constraints USING ybgin (cells);


CREATE TABLE IF NOT EXISTS scd_uss_availability (
id TEXT PRIMARY KEY,
availability TEXT NOT NULL,
updated_at TIMESTAMPTZ NOT NULL
);

CREATE TABLE IF NOT EXISTS schema_versions (
onerow_enforcer bool PRIMARY KEY DEFAULT TRUE CHECK(onerow_enforcer),
schema_version TEXT NOT NULL
onerow_enforcer bool PRIMARY KEY DEFAULT TRUE CHECK(onerow_enforcer),
schema_version TEXT NOT NULL
);

INSERT INTO schema_versions (schema_version) VALUES ('v1.0.0');
12 changes: 0 additions & 12 deletions build/db_schemas/yugabyte/scd/upto-v2.0.0-support_api_1_0_0.sql

This file was deleted.

40 changes: 0 additions & 40 deletions build/db_schemas/yugabyte/scd/upto-v3.0.0-add_inverted_indices.sql

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions build/db_schemas/yugabyte/scd/upto-v3.2.0-add_ovn_columns.sql

This file was deleted.

0 comments on commit 6ba104f

Please sign in to comment.