Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend ctl to database table names #979

Merged
merged 13 commits into from
Aug 17, 2022
20 changes: 10 additions & 10 deletions .fides/dataset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: data_categories
- name: ctl_data_categories
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -213,7 +213,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: data_qualifiers
- name: ctl_data_qualifiers
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -282,7 +282,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: data_subjects
- name: ctl_data_subjects
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -360,7 +360,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: data_uses
- name: ctl_data_uses
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -465,7 +465,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: datasets
- name: ctl_datasets
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -607,7 +607,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: evaluations
- name: ctl_evaluations
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -786,7 +786,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: organizations
- name: ctl_organizations
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -893,7 +893,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: policies
- name: ctl_policies
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -962,7 +962,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: registries
- name: ctl_registries
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down Expand Up @@ -1024,7 +1024,7 @@ dataset:
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
retention: null
fields: null
- name: systems
- name: ctl_systems
description: null
data_categories: null
data_qualifier: aggregated.anonymized.unlinked_pseudonymized.pseudonymized.identified
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The types of changes are:
### Changed

* Upgraded base Docker version to Python 3.9 and updated all other references from 3.8 -> 3.9 [#974](https://github.com/ethyca/fides/pull/974)
* Prepend all database tables with `ctl_` [#979](https://github.com/ethyca/fides/pull/979)
* Moved the `admin-ui` code down one level into a `ctl` subdir [#970](https://github.com/ethyca/fides/pull/970)

## [1.8.1](https://github.com/ethyca/fides/compare/1.8.0...1.8.1) - 2022-08-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,45 @@
branch_labels = None
depends_on = None

SQL_MODEL_LIST = [
"data_categories",
"data_qualifiers",
"data_uses",
"data_subjects",
"datasets",
"evaluations",
"policies",
"registries",
"systems",
"organizations",
]


def upgrade():
for k, model in sql_model_map.items():
allisonking marked this conversation as resolved.
Show resolved Hide resolved
if k not in (
"client_detail",
"fides_user",
"fides_user_permissions",
):
op.add_column(
model.__tablename__,
Column(
"created_at",
DateTime(timezone=True),
server_default=text("now()"),
nullable=True,
),
)
op.add_column(
model.__tablename__,
Column(
"updated_at",
DateTime(timezone=True),
server_default=text("now()"),
nullable=True,
),
)

for table_name in SQL_MODEL_LIST:
op.add_column(
table_name,
Column(
"created_at",
DateTime(timezone=True),
server_default=text("now()"),
nullable=True,
),
)
op.add_column(
table_name,
Column(
"updated_at",
DateTime(timezone=True),
server_default=text("now()"),
nullable=True,
),
)


def downgrade():
for k, model in sql_model_map.items():
if k not in (
"client_detail",
"fides_user",
"fides_user_permissions",
):
op.drop_column(model.__tablename__, "created_at")
op.drop_column(model.__tablename__, "updated_at")

for table_name in SQL_MODEL_LIST:
op.drop_column(table_name, "created_at")
op.drop_column(table_name, "updated_at")
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
"""prepend tables with ctl

Revision ID: aaa81d97a6f6
Revises: f53e04e5b7f5
Create Date: 2022-08-11 09:59:38.709501

"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "aaa81d97a6f6"
down_revision = "f53e04e5b7f5"
branch_labels = None
depends_on = None


def upgrade():
"""Rename tables to avoid collisions with fidesops."""

# Data Categories
op.rename_table("data_categories", "ctl_data_categories")
op.execute("ALTER INDEX data_categories_pkey RENAME TO ctl_data_categories_pkey")
op.execute(
"ALTER INDEX ix_data_categories_fides_key RENAME TO ix_ctl_data_categories_fides_key"
)
op.execute("ALTER INDEX ix_data_categories_id RENAME TO ix_ctl_data_categories_id")

# Data Subjects
op.rename_table("data_subjects", "ctl_data_subjects")
op.execute("ALTER INDEX data_subjects_pkey RENAME TO ctl_data_subjects_pkey")
op.execute(
"ALTER INDEX ix_data_subjects_fides_key RENAME TO ix_ctl_data_subjects_fides_key"
)
op.execute("ALTER INDEX ix_data_subjects_id RENAME TO ix_ctl_data_subjects_id")

# Data Uses
op.rename_table("data_uses", "ctl_data_uses")
op.execute("ALTER INDEX data_uses_pkey RENAME TO ctl_data_uses_pkey")
op.execute(
"ALTER INDEX ix_data_uses_fides_key RENAME TO ix_ctl_data_uses_fides_key"
)
op.execute("ALTER INDEX ix_data_uses_id RENAME TO ix_ctl_data_uses_id")

# Data Qualifiers
op.rename_table("data_qualifiers", "ctl_data_qualifiers")
op.execute("ALTER INDEX data_qualifiers_pkey RENAME TO ctl_data_qualifiers_pkey")
op.execute(
"ALTER INDEX ix_data_qualifiers_fides_key RENAME TO ix_ctl_data_qualifiers_fides_key"
)
op.execute("ALTER INDEX ix_data_qualifiers_id RENAME TO ix_ctl_data_qualifiers_id")

# Datasets
op.rename_table("datasets", "ctl_datasets")
op.execute("ALTER INDEX data_sets_pkey RENAME TO ctl_datasets_pkey")
op.execute("ALTER INDEX ix_datasets_fides_key RENAME TO ix_ctl_datasets_fides_key")
op.execute("ALTER INDEX ix_datasets_id RENAME TO ix_ctl_datasets_id")

# Evaluations
op.rename_table("evaluations", "ctl_evaluations")
op.execute("ALTER INDEX evaluations_pkey RENAME TO ctl_evaluations_pkey")
op.execute(
"ALTER INDEX ix_evaluations_fides_key RENAME TO ix_ctl_evaluations_fides_key"
)
op.execute("ALTER INDEX ix_evaluations_id RENAME TO ix_ctl_evaluations_id")

# Organizations
op.rename_table("organizations", "ctl_organizations")
op.execute("ALTER INDEX organizations_pkey RENAME TO ctl_organizations_pkey")
op.execute(
"ALTER INDEX ix_organizations_fides_key RENAME TO ix_ctl_organizations_fides_key"
)
op.execute("ALTER INDEX ix_organizations_id RENAME TO ix_ctl_organizations_id")

# Policies
op.rename_table("policies", "ctl_policies")
op.execute("ALTER INDEX policies_pkey RENAME TO ctl_policies_pkey")
op.execute("ALTER INDEX ix_policies_fides_key RENAME TO ix_ctl_policies_fides_key")
op.execute("ALTER INDEX ix_policies_id RENAME TO ix_ctl_policies_id")

# Registries
op.rename_table("registries", "ctl_registries")
op.execute("ALTER INDEX registries_pkey RENAME TO ctl_registries_pkey")
op.execute(
"ALTER INDEX ix_registries_fides_key RENAME TO ix_ctl_registries_fides_key"
)
op.execute("ALTER INDEX ix_registries_id RENAME TO ix_ctl_registries_id")

# Systems
op.rename_table("systems", "ctl_systems")
op.execute("ALTER INDEX systems_pkey RENAME TO ctl_systems_pkey")
op.execute("ALTER INDEX ix_systems_fides_key RENAME TO ix_ctl_systems_fides_key")
op.execute("ALTER INDEX ix_systems_id RENAME TO ix_ctl_systems_id")


def downgrade():

op.rename_table("ctl_data_categories", "data_categories")
op.execute("ALTER INDEX ctl_data_categories_pkey RENAME TO data_categories_pkey")
op.execute(
"ALTER INDEX ix_ctl_data_categories_fides_key RENAME TO ix_data_categories_fides_key"
)
op.execute("ALTER INDEX ix_ctl_data_categories_id RENAME TO ix_data_categories_id")

# Data Subjects
op.rename_table("ctl_data_subjects", "data_subjects")
op.execute("ALTER INDEX ctl_data_subjects_pkey RENAME TO data_subjects_pkey")
op.execute(
"ALTER INDEX ix_ctl_data_subjects_fides_key RENAME TO ix_data_subjects_fides_key"
)
op.execute("ALTER INDEX ix_ctl_data_subjects_id RENAME TO ix_data_subjects_id")

# Data Uses
op.rename_table("ctl_data_uses", "data_uses")
op.execute("ALTER INDEX ctl_data_uses_pkey RENAME TO data_uses_pkey")
op.execute(
"ALTER INDEX ix_ctl_data_uses_fides_key RENAME TO ix_data_uses_fides_key"
)
op.execute("ALTER INDEX ix_ctl_data_uses_id RENAME TO ix_data_uses_id")

# Data Qualifiers
op.rename_table("ctl_data_qualifiers", "data_qualifiers")
op.execute("ALTER INDEX ctl_data_qualifiers_pkey RENAME TO data_qualifiers_pkey")
op.execute(
"ALTER INDEX ix_ctl_data_qualifiers_fides_key RENAME TO ix_data_qualifiers_fides_key"
)
op.execute("ALTER INDEX ix_ctl_data_qualifiers_id RENAME TO ix_data_qualifiers_id")

# Datasets
op.rename_table("ctl_datasets", "datasets")
op.execute("ALTER INDEX ctl_datasets_pkey RENAME TO datasets_pkey")
op.execute("ALTER INDEX ix_ctl_datasets_fides_key RENAME TO ix_datasets_fides_key")
op.execute("ALTER INDEX ix_ctl_datasets_id RENAME TO ix_datasets_id")

# Evaluations
op.rename_table("ctl_evaluations", "evaluations")
op.execute("ALTER INDEX ctl_evaluations_pkey RENAME TO evaluations_pkey")
op.execute(
"ALTER INDEX ix_ctl_evaluations_fides_key RENAME TO ix_evaluations_fides_key"
)
op.execute("ALTER INDEX ix_ctl_evaluations_id RENAME TO ix_evaluations_id")

# Organizations
op.rename_table("ctl_organizations", "organizations")
op.execute("ALTER INDEX ctl_organizations_pkey RENAME TO organizations_pkey")
op.execute(
"ALTER INDEX ix_ctl_organizations_fides_key RENAME TO ix_organizations_fides_key"
)
op.execute("ALTER INDEX ix_ctl_organizations_id RENAME TO ix_organizations_id")

# Policies
op.rename_table("ctl_policies", "policies")
op.execute("ALTER INDEX ctl_policies_pkey RENAME TO policies_pkey")
op.execute("ALTER INDEX ix_ctl_policies_fides_key RENAME TO ix_policies_fides_key")
op.execute("ALTER INDEX ix_ctl_policies_id RENAME TO ix_policies_id")

# Registries
op.rename_table("ctl_registries", "registries")
op.execute("ALTER INDEX ctl_registries_pkey RENAME TO registries_pkey")
op.execute(
"ALTER INDEX ix_ctl_registries_fides_key RENAME TO ix_registries_fides_key"
)
op.execute("ALTER INDEX ix_ctl_registries_id RENAME TO ix_registries_id")

# Systems
op.rename_table("ctl_systems", "systems")
op.execute("ALTER INDEX ctl_systems_pkey RENAME TO systems_pkey")
op.execute("ALTER INDEX ix_ctl_systems_fides_key RENAME TO ix_systems_fides_key")
op.execute("ALTER INDEX ix_ctl_systems_id RENAME TO ix_systems_id")
Loading