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

Upgrade local and ephemeral to pg15 #4746

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/postgres/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
db:
image: postgres:14
image: postgres:15
environment:
- DATABASE_NAME=${DATABASE_NAME-postgres}
- POSTGRES_USER=${DATABASE_USER-postgres}
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ watchtower = "==1.0.6" # new version breaks for unknown reason
whitenoise = ">=5.0"
pydantic = ">=2"
sqlparse = "*"
packaging = "*"

[dev-packages]
argh = ">=0.26.2"
Expand Down
578 changes: 289 additions & 289 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4189,7 +4189,7 @@ parameters:
value: koku
- name: DATABASE_VERSION
required: true
value: "14"
value: "15"
- name: CLOWDER_ENABLED
required: true
value: "True"
Expand Down
2 changes: 1 addition & 1 deletion deploy/kustomize/base/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ parameters:
value: koku
- name: DATABASE_VERSION
required: true
value: "14"
value: "15"
- name: CLOWDER_ENABLED
required: true
value: "True"
Expand Down
2 changes: 1 addition & 1 deletion dev/containers/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from postgres:14
from postgres:15

ARG USER_ID=999
ARG GROUP_ID=999
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ services:

db:
container_name: koku-db
image: koku-db:14
image: koku-db:15
build:
context: dev/containers/postgresql
args:
Expand Down
3 changes: 2 additions & 1 deletion koku/masu/api/db_performance/db_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from decimal import Decimal

import psycopg2
from packaging import version
from psycopg2.errors import ProgrammingError
from psycopg2.extras import RealDictCursor
from sqlparse import format as sql_format
Expand Down Expand Up @@ -197,7 +198,7 @@ def get_statement_stats(self, dbname, limit=100, offset=None):

limit_clause = self._handle_limit(limit, params)
offset_clause = self._handle_offset(offset, params)
col_name_sep = "_" if Decimal(pss_ver) < Decimal("1.8") else "_exec_"
col_name_sep = "_" if version.parse(pss_ver) < version.parse("1.8") else "_exec_"
params["dbname"] = dbname
sql = f"""
-- STATEMENT STATISTICS
Expand Down
38 changes: 22 additions & 16 deletions koku/masu/database/report_db_accessor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,29 @@ def delete_line_item_daily_summary_entries_for_date_range_raw(
msg = f"Deleting records from {table} for source {source_uuid} from {start_date} to {end_date}"
LOG.info(msg)

sql = f"""
DELETE FROM {self.schema}.{table}
WHERE usage_start >= %(start_date)s::date
AND usage_start <= %(end_date)s::date
filters = filters or {} # convert None -> dict
null_filters = null_filters or {} # convert None -> dict

tmp_sql = """
DELETE FROM {{schema | sqlsafe}}.{{table | sqlsafe}}
WHERE usage_start >= {{start_date}}
AND usage_start <= {{end_date}}
{% for k, v in filters.items() -%}
AND {{ k | sqlsafe }} = {{ v }}
{% endfor -%}
{% for k, v in null_filters.items() -%}
AND {{ k | sqlsafe }} {{ v | sqlsafe }}
{% endfor -%}
"""
if filters:
filter_list = [f"AND {k} = %({k})s" for k in filters]
sql += "\n".join(filter_list)
else:
filters = {}
if null_filters:
filter_list = [f"AND {column} {null_filter}" for column, null_filter in null_filters.items()]
sql += "\n".join(filter_list)
filters["start_date"] = start_date
filters["end_date"] = end_date

self._execute_raw_sql_query(table, sql, bind_params=filters, operation="DELETE")
tmp_sql_params = {
"schema": self.schema,
"table": table,
"start_date": start_date,
"end_date": end_date,
"filters": filters,
"null_filters": null_filters,
}
self._prepare_and_execute_raw_sql_query(table, tmp_sql, tmp_sql_params, operation="DELETE")

def truncate_partition(self, partition_name):
"""Issue a TRUNCATE command on a specific partition of a table"""
Expand Down
Loading