Skip to content

Commit

Permalink
updated sqlalchemy to 1.4 using a up-to-date query syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Chubatiuk committed Dec 22, 2023
1 parent 30b59eb commit 3b9234b
Show file tree
Hide file tree
Showing 103 changed files with 2,346 additions and 1,348 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
docker compose up -d
sleep 10
- name: Create Test Database
run: docker compose -p redash run --rm postgres psql -h postgres -U postgres -c "create database tests;"
run: docker compose run --rm postgres psql -h postgres -U postgres -c "create database tests;"
- name: List Enabled Query Runners
run: docker compose -p redash run --rm redash manage ds list_types
run: docker compose run --rm redash manage ds list_types
- name: Run Tests
run: docker compose -p redash run --name tests redash tests --junitxml=junit.xml --cov-report=xml --cov=redash --cov-config=.coveragerc tests/
run: docker compose run --name tests redash tests --junitxml=junit.xml --cov-report=xml --cov=redash --cov-config=.coveragerc tests/
- name: Copy Test Results
run: |
mkdir -p /tmp/test-results/unit-tests
Expand Down Expand Up @@ -137,6 +137,7 @@ jobs:
set -x
yarn cypress build
yarn cypress start -- --skip-db-seed
docker compose run server create_db
docker compose run cypress yarn cypress db-seed
- name: Execute Cypress Tests
run: yarn cypress run-ci
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/items-list/classes/ItemsFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class PaginatedListFetcher extends ItemsFetcher {
return this._originalGetRequest(
{
page: paginator.page,
page_size: paginator.itemsPerPage,
per_page: paginator.itemsPerPage,
order: sorter.compiled,
q: isString(searchTerm) && searchTerm !== "" ? searchTerm : undefined,
tags: selectedTags,
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/items-list/classes/ItemsSource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type GetResourceRequest = any; // TODO: Add stricter type
export interface ItemsPage<INPUT = any> {
count: number;
page: number;
page_size: number;
per_page: number;
results: INPUT[];
}

Expand Down
4 changes: 2 additions & 2 deletions client/app/components/items-list/classes/StateStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class UrlStateStorage extends StateStorage {

return {
page: parseInt(params.page, 10) || defaultState.page,
itemsPerPage: parseInt(params.page_size, 10) || defaultState.itemsPerPage,
itemsPerPage: parseInt(params.per_page, 10) || defaultState.itemsPerPage,
orderByField,
orderByReverse,
searchTerm,
Expand All @@ -50,7 +50,7 @@ export class UrlStateStorage extends StateStorage {
location.setSearch(
{
page,
page_size: itemsPerPage,
per_page: itemsPerPage,
order: compileOrderBy(orderByField, orderByReverse),
q: searchTerm !== "" ? searchTerm : null,
},
Expand Down
16 changes: 8 additions & 8 deletions migrations/versions/640888ce445d_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table

from redash.models import MutableDict, PseudoJSON
from sqlalchemy.dialects.postgresql import JSON
from redash.models import MutableDict


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -41,7 +41,7 @@ def upgrade():
"queries",
sa.Column(
"schedule",
MutableDict.as_mutable(PseudoJSON),
MutableDict.as_mutable(JSON),
nullable=False,
server_default=json.dumps({}),
),
Expand All @@ -51,7 +51,7 @@ def upgrade():
queries = table(
"queries",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("schedule", MutableDict.as_mutable(PseudoJSON)),
sa.Column("schedule", MutableDict.as_mutable(JSON)),
sa.Column("old_schedule", sa.String(length=10)),
)

Expand Down Expand Up @@ -85,16 +85,16 @@ def downgrade():
"queries",
sa.Column(
"old_schedule",
MutableDict.as_mutable(PseudoJSON),
MutableDict.as_mutable(JSON),
nullable=False,
server_default=json.dumps({}),
),
)

queries = table(
"queries",
sa.Column("schedule", MutableDict.as_mutable(PseudoJSON)),
sa.Column("old_schedule", MutableDict.as_mutable(PseudoJSON)),
sa.Column("schedule", MutableDict.as_mutable(JSON)),
sa.Column("old_schedule", MutableDict.as_mutable(JSON)),
)

op.execute(queries.update().values({"old_schedule": queries.c.schedule}))
Expand All @@ -106,7 +106,7 @@ def downgrade():
"queries",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("schedule", sa.String(length=10)),
sa.Column("old_schedule", MutableDict.as_mutable(PseudoJSON)),
sa.Column("old_schedule", MutableDict.as_mutable(JSON)),
)

conn = op.get_bind()
Expand Down
6 changes: 3 additions & 3 deletions migrations/versions/73beceabb948_bring_back_null_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.sql import table

from redash.models import MutableDict, PseudoJSON
from redash.models import MutableDict

# revision identifiers, used by Alembic.
revision = "73beceabb948"
Expand Down Expand Up @@ -43,7 +43,7 @@ def upgrade():
queries = table(
"queries",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("schedule", MutableDict.as_mutable(PseudoJSON)),
sa.Column("schedule", MutableDict.as_mutable(JSON)),
)

conn = op.get_bind()
Expand Down
8 changes: 4 additions & 4 deletions migrations/versions/969126bd800f_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import simplejson
import json
from alembic import op
import sqlalchemy as sa

Expand All @@ -27,7 +27,7 @@ def upgrade():
dashboard_result = db.session.execute("SELECT id, layout FROM dashboards")
for dashboard in dashboard_result:
print(" Updating dashboard: {}".format(dashboard["id"]))
layout = simplejson.loads(dashboard["layout"])
layout = json.loads(dashboard["layout"])

print(" Building widgets map:")
widgets = {}
Expand All @@ -53,7 +53,7 @@ def upgrade():
if widget is None:
continue

options = simplejson.loads(widget["options"]) or {}
options = json.loads(widget["options"]) or {}
options["position"] = {
"row": row_index,
"col": column_index * column_size,
Expand All @@ -62,7 +62,7 @@ def upgrade():

db.session.execute(
"UPDATE widgets SET options=:options WHERE id=:id",
{"options": simplejson.dumps(options), "id": widget_id},
{"options": json.dumps(options), "id": widget_id},
)

dashboard_result.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
from redash.utils.configuration import ConfigurationContainer
from redash.models.types import (
EncryptedConfiguration,
Configuration,
MutableDict,
MutableList,
PseudoJSON,
)

# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -46,7 +44,14 @@ def upgrade():
)
),
),
sa.Column("options", ConfigurationContainer.as_mutable(Configuration)),
sa.Column(
"options",
ConfigurationContainer.as_mutable(
EncryptedConfiguration(
sa.Text, settings.DATASOURCE_SECRET_KEY, FernetEngine
)
)
),
)

conn = op.get_bind()
Expand Down
10 changes: 8 additions & 2 deletions migrations/versions/d7d747033183_encrypt_alert_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from redash.models.base import key_type
from redash.models.types import (
EncryptedConfiguration,
Configuration,
)


Expand Down Expand Up @@ -45,7 +44,14 @@ def upgrade():
)
),
),
sa.Column("options", ConfigurationContainer.as_mutable(Configuration)),
sa.Column(
"options",
ConfigurationContainer.as_mutable(
EncryptedConfiguration(
sa.Text, settings.DATASOURCE_SECRET_KEY, FernetEngine
)
)
),
)

conn = op.get_bind()
Expand Down

0 comments on commit 3b9234b

Please sign in to comment.