Skip to content

Commit

Permalink
sqlalchemy 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Chubatiuk committed Dec 23, 2023
1 parent 858fc4d commit bfd23f6
Show file tree
Hide file tree
Showing 103 changed files with 1,396 additions and 1,321 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
4 changes: 2 additions & 2 deletions migrations/versions/0ec979123ba4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSON

# revision identifiers, used by Alembic.
revision = '0ec979123ba4'
Expand All @@ -18,7 +18,7 @@

def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('dashboards', sa.Column('options', postgresql.JSON(astext_type=sa.Text()), server_default='{}', nullable=False))
op.add_column('dashboards', sa.Column('options', JSON(astext_type=sa.Text()), server_default='{}', nullable=False))
# ### end Alembic commands ###


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 @@ -7,18 +7,16 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import BYTEA
from sqlalchemy.sql import table
from sqlalchemy_utils.types.encrypted.encrypted_type import FernetEngine

from redash import settings
from redash.utils.configuration import ConfigurationContainer
from redash.models.types import (
EncryptedConfiguration,
Configuration,
MutableDict,
MutableList,
PseudoJSON,
)

# revision identifiers, used by Alembic.
Expand All @@ -31,7 +29,7 @@
def upgrade():
op.add_column(
"data_sources",
sa.Column("encrypted_options", postgresql.BYTEA(), nullable=True),
sa.Column("encrypted_options", BYTEA(), nullable=True),
)

# copy values
Expand All @@ -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
6 changes: 3 additions & 3 deletions migrations/versions/a92d92aa678e_inline_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from funcy import flatten, compact
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import ARRAY
from redash import models

# revision identifiers, used by Alembic.
Expand All @@ -21,10 +21,10 @@

def upgrade():
op.add_column(
"dashboards", sa.Column("tags", postgresql.ARRAY(sa.Unicode()), nullable=True)
"dashboards", sa.Column("tags", ARRAY(sa.Unicode()), nullable=True)
)
op.add_column(
"queries", sa.Column("tags", postgresql.ARRAY(sa.Unicode()), nullable=True)
"queries", sa.Column("tags", ARRAY(sa.Unicode()), nullable=True)
)


Expand Down
14 changes: 10 additions & 4 deletions migrations/versions/d7d747033183_encrypt_alert_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import BYTEA
from sqlalchemy.sql import table
from sqlalchemy_utils.types.encrypted.encrypted_type import FernetEngine

Expand All @@ -16,7 +16,6 @@
from redash.models.base import key_type
from redash.models.types import (
EncryptedConfiguration,
Configuration,
)


Expand All @@ -30,7 +29,7 @@
def upgrade():
op.add_column(
"notification_destinations",
sa.Column("encrypted_options", postgresql.BYTEA(), nullable=True)
sa.Column("encrypted_options", BYTEA(), nullable=True)
)

# copy values
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSON

# revision identifiers, used by Alembic.
revision = "e7f8a917aa8e"
Expand All @@ -21,7 +21,7 @@ def upgrade():
"users",
sa.Column(
"details",
postgresql.JSON(astext_type=sa.Text()),
JSON(astext_type=sa.Text()),
server_default="{}",
nullable=True,
),
Expand Down
10 changes: 5 additions & 5 deletions migrations/versions/fd4fc850d7ea_.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import JSON, JSONB

from redash.models import db

Expand All @@ -23,8 +23,8 @@ def upgrade():

### commands auto generated by Alembic - please adjust! ###
op.alter_column('users', 'details',
existing_type=postgresql.JSON(astext_type=sa.Text()),
type_=postgresql.JSONB(astext_type=sa.Text()),
existing_type=JSON(astext_type=sa.Text()),
type_=JSONB(astext_type=sa.Text()),
existing_nullable=True,
existing_server_default=sa.text("'{}'::jsonb"))
### end Alembic commands ###
Expand Down Expand Up @@ -52,8 +52,8 @@ def downgrade():
connection.execute(update_query)
db.session.commit()
op.alter_column('users', 'details',
existing_type=postgresql.JSONB(astext_type=sa.Text()),
type_=postgresql.JSON(astext_type=sa.Text()),
existing_type=JSONB(astext_type=sa.Text()),
type_=JSON(astext_type=sa.Text()),
existing_nullable=True,
existing_server_default=sa.text("'{}'::json"))

Expand Down

0 comments on commit bfd23f6

Please sign in to comment.