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

[COST-2231] Upgrade to Django 4 #4844

Merged
merged 11 commits into from
Feb 19, 2024
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ celery = ">=5.2.2"
ciso8601 = ">=2.1"
confluent-kafka = ">=2.1.0"
croniter = "*"
Django = "<4.0"
Django = "~=4.2.0"
django-cors-headers = ">=3.1"
django-environ = ">=0.4"
django-extensions = ">=2.2"
django-filter = ">=2.2"
django-prometheus = ">=1.1"
django-redis = ">=4.10"
django-tenants = ">=3.4"
djangorestframework = ">=3.11,!=3.14.0"
djangorestframework = ">=3.14.0"
djangorestframework-csv = ">=2.1"
google-api-python-client = ">=1.12.4"
google-auth = ">=1.22.1"
Expand All @@ -50,6 +49,7 @@ psycopg2 = ">=2.9"
pyarrow = ">=0.17.1"
python-dateutil = ">=2.8"
querystring-parser = ">=1.2"
redis = ">=5.0.1"
requests = ">=2.20"
sentry-sdk = ">=0.13"
statsmodels = ">=0.12"
Expand Down
72 changes: 32 additions & 40 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 7 additions & 86 deletions db_functions/clone_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ CREATE OR REPLACE FUNCTION public.clone_schema(
_verbose boolean DEFAULT false
) RETURNS boolean AS $$
DECLARE
sequence_objects jsonb[];
sequence_owner_info jsonb[];
table_objects jsonb[];
fk_objects jsonb[];
Expand Down Expand Up @@ -55,32 +54,6 @@ BEGIN
/*
* Gather data for copy
*/
/* Sequence objects */
IF _verbose THEN
RAISE INFO 'Gathering sequence object data from %...', source_schema;
END IF;

SELECT coalesce(array_agg(
jsonb_build_object(
'sequence_name', c.relname,
'sequence_type', s.seqtypid::regtype::text,
'sequence_start', s.seqstart,
'sequence_inc', s.seqincrement,
'sequence_max', s.seqmax,
'sequence_min', s.seqmin,
'sequence_cache', s.seqcache,
'sequence_cycle', CASE WHEN s.seqcycle THEN ' CYCLE' ELSE ' NO CYCLE' END::text
)
), '{}'::jsonb[])
INTO sequence_objects
FROM pg_sequence s
JOIN pg_class c
ON c.oid = s.seqrelid
WHERE c.relnamespace = source_schema::regnamespace;

IF _verbose THEN
RAISE INFO ' Got %s schema objects...', cardinality(sequence_objects);
END IF;

/* Sequence owner info */
IF _verbose THEN
Expand Down Expand Up @@ -388,48 +361,6 @@ BEGIN
END IF;
EXECUTE 'CREATE SCHEMA ' || dst_schema || ' ;';

/*
* Create sequences
*/
IF cardinality(sequence_objects) > 0
maskarb marked this conversation as resolved.
Show resolved Hide resolved
THEN
IF _verbose
THEN
RAISE INFO 'Creating sequences for %', dst_schema;
END IF;
FOREACH jobject IN ARRAY sequence_objects
LOOP
IF _verbose
THEN
RAISE INFO ' %.%', dst_schema, quote_ident(jobject->>'sequence_name'::text);
END IF;
EXECUTE FORMAT('CREATE SEQUENCE IF NOT EXISTS %s.%I AS %s START WITH %s INCREMENT BY %s MINVALUE %s MAXVALUE %s CACHE %s %s ;',
dst_schema,
jobject->>'sequence_name'::text,
jobject->>'sequence_type'::text,
jobject->>'sequence_start'::text,
jobject->>'sequence_inc'::text,
jobject->>'sequence_min'::text,
jobject->>'sequence_max'::text,
jobject->>'sequence_cache'::text,
jobject->>'sequence_cycle');

IF copy_data OR
(jobject->>'sequence_name' ~ 'partitioned_tables'::text) OR
(jobject->>'sequence_name' ~ 'django_migrations'::text)
THEN
EXECUTE 'SELECT setval(''' || dst_schema || '.' || quote_ident(jobject->>'sequence_name') || '''::regclass, '::text ||
'(SELECT last_value + 1 FROM ' ||
src_schema || '.' || quote_ident(jobject->>'sequence_name') || ') );'::text;
END IF;
END LOOP;
ELSE
IF _verbose
THEN
RAISE INFO 'No sequences for %', dst_schema;
END IF;
END IF;

/*
* Create tables
*/
Expand Down Expand Up @@ -509,37 +440,27 @@ BEGIN
END IF;

/*
* Create sequence owner links
* Set sequence value
*/
IF cardinality(sequence_owner_info) > 0
THEN
IF _verbose
THEN
RAISE INFO 'Setting sequence ownership for objects in %', dst_schema;
RAISE INFO 'Set current value for sequence objects in %', dst_schema;
END IF;
FOREACH jobject IN ARRAY sequence_owner_info
LOOP
IF _verbose
THEN
RAISE INFO ' Update primary key default for %.%', dst_schema, quote_ident(jobject->>'owner_object'::text);
RAISE INFO ' Update sequence value for %.%', dst_schema, quote_ident(jobject->>'owner_object'::text);
END IF;
EXECUTE FORMAT('ALTER TABLE %s.%I ALTER COLUMN %I SET DEFAULT nextval( ''%s.%I''::regclass );',
dst_schema,
jobject->>'owner_object'::text,
jobject->>'owner_column'::text,
dst_schema,
jobject->>'sequence_name'::text);

IF _verbose
THEN
RAISE INFO ' Update sequence owned-by table column to %."%"', dest_obj, jobject->>'owner_column'::text;
END IF;
EXECUTE FORMAT('ALTER SEQUENCE %s.%I OWNED BY %s.%I.%I ;',
EXECUTE FORMAT('SELECT setval(''%s.%I'', (SELECT max(%I) FROM %s.%I));',
dst_schema,
jobject->>'sequence_name'::text,
dest_schema,
jobject->>'owner_object'::text,
jobject->>'owner_column'::text);
jobject->>'owner_column'::text,
dst_schema,
jobject->>'owner_object'::text);
END LOOP;
ELSE
IF _verbose
Expand Down
4 changes: 2 additions & 2 deletions koku/api/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# noqa
from uuid import UUID

from django.utils.translation import ugettext as _
from django.utils.translation import gettext

RH_IDENTITY_HEADER = "HTTP_X_RH_IDENTITY"

Expand All @@ -11,7 +11,7 @@

def error_obj(key, message):
"""Create an error object."""
return {key: [_(message)]}
return {key: [gettext(message)]}


def log_json(tracing_id="", *, msg, context=None, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions koku/api/dataexport/syncer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dateutil.rrule import MONTHLY
from dateutil.rrule import rrule
from django.conf import settings
from django.utils.translation import gettext as _
from django.utils.translation import gettext

from api.provider.models import Provider

Expand Down Expand Up @@ -85,15 +85,15 @@ def _copy_object(self, s3_destination_bucket, source_object):
if source_object.storage_class == "GLACIER" and e.response["Error"]["Code"] == "InvalidObjectState":
request = {"Days": 2, "GlacierJobParameters": {"Tier": "Standard"}}
source_object.restore_object(RestoreRequest=request)
LOG.info(_("Glacier Storage restore for %s is in progress."), source_object.key)
LOG.info(gettext("Glacier Storage restore for %s is in progress."), source_object.key)
raise SyncedFileInColdStorageError(
f"Requested file {source_object.key} is currently in AWS Glacier Storage, "
f"an request has been made to restore the file."
)
# if object cannot be copied because restore is already in progress raise
# SyncedFileInColdStorageError and wait a while longer
elif e.response["Error"]["Code"] == "RestoreAlreadyInProgress":
LOG.info(_("Glacier Storage restore for %s is in progress."), source_object.key)
LOG.info(gettext("Glacier Storage restore for %s is in progress."), source_object.key)
raise SyncedFileInColdStorageError(
f"Requested file {source_object.key} has not yet been restored from AWS Glacier Storage."
)
Expand Down
Loading
Loading