Skip to content

Commit 17725eb

Browse files
authored
chore: use logger on all migrations (#34521)
1 parent 1a7a381 commit 17725eb

25 files changed

+72
-45
lines changed

superset/migrations/shared/catalogs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838
from superset.models.core import Database
3939

40-
logger = logging.getLogger("alembic")
40+
logger = logging.getLogger("alembic.env")
4141

4242
Base: Type[Any] = declarative_base()
4343

superset/migrations/shared/migrate_viz/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from superset.utils import json
2929
from superset.utils.date_parser import get_since_until
3030

31-
logger = logging.getLogger("alembic")
31+
logger = logging.getLogger("alembic.env")
3232

3333
Base = declarative_base()
3434

superset/migrations/shared/security_converge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from sqlalchemy.ext.declarative import declarative_base
3030
from sqlalchemy.orm import Load, relationship, Session
3131

32-
logger = logging.getLogger(__name__)
32+
logger = logging.getLogger("alembic.env")
3333

3434
Base = declarative_base()
3535

superset/migrations/shared/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
RED = "\033[31m"
5050
LRED = "\033[91m"
5151

52-
logger = logging.getLogger("alembic")
52+
logger = logging.getLogger("alembic.env")
5353

5454
DEFAULT_BATCH_SIZE = int(os.environ.get("BATCH_SIZE", 1000))
5555

superset/migrations/versions/2016-05-27_15-03_1226819ee0e3_fix_wrong_constraint_on_table_columns.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
revision = "1226819ee0e3"
3434
down_revision = "956a063c52b3"
3535

36+
logger = logging.getLogger("alembic.env")
37+
3638

3739
naming_convention = {
3840
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s"
@@ -61,7 +63,7 @@ def upgrade():
6163
["datasource_name"],
6264
)
6365
except: # noqa: E722
64-
logging.warning("Could not find or drop constraint on `columns`")
66+
logger.warning("Could not find or drop constraint on `columns`")
6567

6668

6769
def downgrade():

superset/migrations/versions/2016-09-22_10-21_3b626e2a6783_sync_db_with_models.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
revision = "3b626e2a6783"
3939
down_revision = "eca4694defa7"
4040

41+
logger = logging.getLogger("alembic.env")
42+
4143

4244
def upgrade():
4345
# cleanup after: https://github.com/airbnb/superset/pull/1078
@@ -60,7 +62,7 @@ def upgrade():
6062
batch_op.drop_column("druid_datasource_id")
6163
batch_op.drop_column("table_id")
6264
except Exception as ex:
63-
logging.warning(str(ex))
65+
logger.warning(str(ex))
6466

6567
# fixed issue: https://github.com/airbnb/superset/issues/466
6668
try:
@@ -69,26 +71,26 @@ def upgrade():
6971
None, "datasources", ["datasource_name"], ["datasource_name"]
7072
)
7173
except Exception as ex:
72-
logging.warning(str(ex))
74+
logger.warning(str(ex))
7375
try:
7476
with op.batch_alter_table("query") as batch_op:
7577
batch_op.create_unique_constraint("client_id", ["client_id"])
7678
except Exception as ex:
77-
logging.warning(str(ex))
79+
logger.warning(str(ex))
7880

7981
try:
8082
with op.batch_alter_table("query") as batch_op:
8183
batch_op.drop_column("name")
8284
except Exception as ex:
83-
logging.warning(str(ex))
85+
logger.warning(str(ex))
8486

8587

8688
def downgrade():
8789
try:
8890
with op.batch_alter_table("tables") as batch_op:
8991
batch_op.create_index("table_name", ["table_name"], unique=True)
9092
except Exception as ex:
91-
logging.warning(str(ex))
93+
logger.warning(str(ex))
9294

9395
try:
9496
with op.batch_alter_table("slices") as batch_op:
@@ -113,7 +115,7 @@ def downgrade():
113115
)
114116
batch_op.create_foreign_key("slices_ibfk_2", "tables", ["table_id"], ["id"])
115117
except Exception as ex:
116-
logging.warning(str(ex))
118+
logger.warning(str(ex))
117119

118120
try:
119121
fk_columns = generic_find_constraint_name(
@@ -125,11 +127,11 @@ def downgrade():
125127
with op.batch_alter_table("columns") as batch_op:
126128
batch_op.drop_constraint(fk_columns, type_="foreignkey")
127129
except Exception as ex:
128-
logging.warning(str(ex))
130+
logger.warning(str(ex))
129131

130132
op.add_column("query", sa.Column("name", sa.String(length=256), nullable=True))
131133
try:
132134
with op.batch_alter_table("query") as batch_op:
133135
batch_op.drop_constraint("client_id", type_="unique")
134136
except Exception as ex:
135-
logging.warning(str(ex))
137+
logger.warning(str(ex))

superset/migrations/versions/2016-10-05_11-30_b46fa1b0b39e_add_params_to_tables.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import sqlalchemy as sa # noqa: E402
3232
from alembic import op # noqa: E402
3333

34+
logger = logging.getLogger("alembic.env")
35+
3436

3537
def upgrade():
3638
op.add_column("tables", sa.Column("params", sa.Text(), nullable=True))
@@ -40,4 +42,4 @@ def downgrade():
4042
try:
4143
op.drop_column("tables", "params")
4244
except Exception as ex:
43-
logging.warning(str(ex))
45+
logger.warning(str(ex))

superset/migrations/versions/2017-03-16_18-10_db527d8c4c78_add_db_verbose_name.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import sqlalchemy as sa # noqa: E402
3232
from alembic import op # noqa: E402
3333

34+
logger = logging.getLogger("alembic.env")
35+
3436

3537
def upgrade():
3638
op.add_column(
@@ -44,12 +46,12 @@ def upgrade():
4446
op.create_unique_constraint(None, "dbs", ["verbose_name"])
4547
op.create_unique_constraint(None, "clusters", ["verbose_name"])
4648
except Exception:
47-
logging.info("Constraint not created, expected when using sqlite")
49+
logger.info("Constraint not created, expected when using sqlite")
4850

4951

5052
def downgrade():
5153
try:
5254
op.drop_column("dbs", "verbose_name")
5355
op.drop_column("clusters", "verbose_name")
5456
except Exception as ex:
55-
logging.exception(ex)
57+
logger.exception(ex)

superset/migrations/versions/2017-10-03_14-37_4736ec66ce19_.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
revision = "4736ec66ce19"
3838
down_revision = "f959a6652acd"
3939

40+
logger = logging.getLogger("alembic.env")
41+
4042
conv = {
4143
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
4244
"uq": "uq_%(table_name)s_%(column_0_name)s",
@@ -119,13 +121,13 @@ def upgrade():
119121
type_="unique",
120122
)
121123
except Exception as ex:
122-
logging.warning(
124+
logger.warning(
123125
"Constraint drop failed, you may want to do this "
124126
"manually on your database. For context, this is a known "
125127
"issue around nondeterministic constraint names on Postgres "
126128
"and perhaps more databases through SQLAlchemy."
127129
)
128-
logging.exception(ex)
130+
logger.exception(ex)
129131

130132

131133
def downgrade():

superset/migrations/versions/2018-05-09_23-45_e502db2af7be_add_template_params_to_tables.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
2323
"""
2424

25+
import logging
26+
27+
import sqlalchemy as sa # noqa: E402
28+
from alembic import op # noqa: E402
29+
2530
# revision identifiers, used by Alembic.
2631
revision = "e502db2af7be"
2732
down_revision = "5ccf602336a0"
2833

29-
import sqlalchemy as sa # noqa: E402
30-
from alembic import op # noqa: E402
34+
logger = logging.getLogger("alembic.env")
3135

3236

3337
def upgrade():
@@ -38,4 +42,4 @@ def downgrade():
3842
try:
3943
op.drop_column("tables", "template_params")
4044
except Exception as ex:
41-
logging.warning(str(ex)) # noqa: F821
45+
logger.warning(str(ex))

0 commit comments

Comments
 (0)