Skip to content

Commit

Permalink
Cost 1329 initial enabled keys migration (project-koku#3716)
Browse files Browse the repository at this point in the history
* Migration to add 'enabled' column

* initial migration

* fix sql

* update PR template
  • Loading branch information
Red-HAP authored Jun 28, 2022
1 parent b09ffc9 commit 45a714b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 16 deletions.
31 changes: 15 additions & 16 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
Fixes [COST-####](https://issues.redhat.com/browse/COST-####)
## Jira Ticket

Changes proposed in this PR:
*
*
[COST-####](https://issues.redhat.com/browse/COST-####)

Testing Instructions:
1. Run `this command` ...
2. Ingest this data `with this other command` ...
3. Expect to see this result:
```
GET http://localhost:8000/api/endpoint
## Description

{json: response}
```
4.
5.
This change will ...

---
Additional Context:
## Testing

1. Checkout Branch
2. Restart Koku
3. Hit endpoint or launch shell
1. You should see ...
4. Do more things...

## Notes

...
83 changes: 83 additions & 0 deletions koku/reporting/migrations/0256_enabled_keys_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Generated by Django 3.2.13 on 2022-06-17 19:32
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [("reporting", "0255_ocp_label_indices")]

operations = [
migrations.RunSQL(
sql="""
alter table reporting_azureenabledtagkeys
add column enabled boolean not null default true;
create index azure_enabled_covering_ix
on reporting_azureenabledtagkeys (key, enabled);
""",
reverse_sql="""
drop index azure_enabled_covering_ix;
alter table reporting_azureenabledtagkeys
drop column enabled;
""",
state_operations=[
migrations.AddField(
model_name="azureenabledtagkeys",
name="enabled",
field=models.BooleanField(default=True),
),
migrations.AddIndex(
model_name="azureenabledtagkeys",
index=models.Index(fields=["key", "enabled"], name="azure_enabled_covering_ix"),
),
],
),
migrations.RunSQL(
sql="""
alter table reporting_gcpenabledtagkeys
add column enabled boolean not null default true;
create index gcp_enabled_covering_ix
on reporting_gcpenabledtagkeys (key, enabled);
""",
reverse_sql="""
drop index gcp_enabled_covering_ix;
alter table reporting_gcpenabledtagkeys
drop column enabled;
""",
state_operations=[
migrations.AddField(
model_name="gcpenabledtagkeys",
name="enabled",
field=models.BooleanField(default=True),
),
migrations.AddIndex(
model_name="gcpenabledtagkeys",
index=models.Index(fields=["key", "enabled"], name="gcp_enabled_covering_ix"),
),
],
),
migrations.RunSQL(
sql="""
alter table reporting_ocpenabledtagkeys
add column enabled boolean not null default true;
create index ocp_enabled_covering_ix
on reporting_ocpenabledtagkeys (key, enabled);
""",
reverse_sql="""
drop index ocp_enabled_covering_ix;
alter table reporting_ocpenabledtagkeys
drop column enabled;
""",
state_operations=[
migrations.AddField(
model_name="ocpenabledtagkeys",
name="enabled",
field=models.BooleanField(default=True),
),
migrations.AddIndex(
model_name="ocpenabledtagkeys",
index=models.Index(fields=["key", "enabled"], name="ocp_enabled_covering_ix"),
),
],
),
]
2 changes: 2 additions & 0 deletions koku/reporting/provider/azure/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ class Meta:
"""Meta for AzureEnabledTagKeys."""

db_table = "reporting_azureenabledtagkeys"
indexes = [models.Index(name="azure_enabled_covering_ix", fields=["key", "enabled"])]

id = models.BigAutoField(primary_key=True)
key = models.CharField(max_length=253, unique=True)
enabled = models.BooleanField(null=False, default=True)


# ======================================================
Expand Down
2 changes: 2 additions & 0 deletions koku/reporting/provider/gcp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ class Meta:
"""Meta for GCPEnabledTagKeys."""

db_table = "reporting_gcpenabledtagkeys"
indexes = [models.Index(name="gcp_enabled_covering_ix", fields=["key", "enabled"])]

id = models.BigAutoField(primary_key=True)
key = models.CharField(max_length=253, unique=True)
enabled = models.BooleanField(null=False, default=True)


class GCPTagsSummary(models.Model):
Expand Down
2 changes: 2 additions & 0 deletions koku/reporting/provider/ocp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,11 @@ class Meta:
"""Meta for OCPEnabledTagKeys."""

db_table = "reporting_ocpenabledtagkeys"
indexes = [models.Index(name="ocp_enabled_covering_ix", fields=["key", "enabled"])]

id = models.BigAutoField(primary_key=True)
key = models.CharField(max_length=253, unique=True)
enabled = models.BooleanField(null=False, default=True)


class OCPCluster(models.Model):
Expand Down

0 comments on commit 45a714b

Please sign in to comment.