Skip to content

Commit a0307b2

Browse files
Merge pull request #120 from lsst/tickets/DM-47256
DM-47256: Remove apply_schema_to_tables flag
2 parents d239b8a + 4fb1013 commit a0307b2

File tree

9 files changed

+15
-29
lines changed

9 files changed

+15
-29
lines changed

docs/changes/DM-47256.removal.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the ``apply_schema_to_tables`` flag on the ``MetaDataBuilder`` which creates SQLAlchemy ``MetaData`` from a Felis ``Schema``.
2+
This is a redundant variable as enabling the ``apply_schema_to_metadata`` flag already correctly associates the metadata to the schema.
File renamed without changes.

python/felis/db/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ def create_database(schema: Schema, engine_or_url_str: Engine | str | None = Non
5353
)
5454
else:
5555
engine = create_engine("sqlite:///:memory:")
56-
apply_schema = False if engine.url.drivername == "sqlite" else True
5756
metadata = MetaDataBuilder(
58-
schema, apply_schema_to_metadata=apply_schema, apply_schema_to_tables=apply_schema
57+
schema, apply_schema_to_metadata=False if engine.url.drivername == "sqlite" else True
5958
).build()
6059
ctx = DatabaseContext(metadata, engine)
6160
ctx.initialize()

python/felis/diff.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ def __init__(self, schema: Schema, engine: Engine):
218218
mc = MigrationContext.configure(
219219
connection, opts={"compare_type": True, "target_metadata": db_metadata}
220220
)
221-
schema_metadata = MetaDataBuilder(
222-
schema, apply_schema_to_metadata=False, apply_schema_to_tables=False
223-
).build()
221+
schema_metadata = MetaDataBuilder(schema, apply_schema_to_metadata=False).build()
224222
self.diff = compare_metadata(mc, schema_metadata)
225223

226224
def print(self) -> None:

python/felis/metadata.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ class MetaDataBuilder:
125125
The schema object from which to build the SQLAlchemy metadata.
126126
apply_schema_to_metadata
127127
Whether to apply the schema name to the metadata object.
128-
apply_schema_to_tables
129-
Whether to apply the schema name to the tables.
130128
ignore_constraints
131129
Whether to ignore constraints when building the metadata.
132130
"""
@@ -135,18 +133,14 @@ def __init__(
135133
self,
136134
schema: Schema,
137135
apply_schema_to_metadata: bool = True,
138-
apply_schema_to_tables: bool = True,
139136
ignore_constraints: bool = False,
140137
) -> None:
141138
"""Initialize the metadata builder."""
142139
self.schema = schema
143140
if not apply_schema_to_metadata:
144141
logger.debug("Schema name will not be applied to metadata")
145-
if not apply_schema_to_tables:
146-
logger.debug("Schema name will not be applied to tables")
147142
self.metadata = MetaData(schema=schema.name if apply_schema_to_metadata else None)
148143
self._objects: dict[str, Any] = {}
149-
self.apply_schema_to_tables = apply_schema_to_tables
150144
self.ignore_constraints = ignore_constraints
151145

152146
def build(self) -> MetaData:
@@ -235,7 +229,6 @@ def build_table(self, table_obj: datamodel.Table) -> None:
235229
self.metadata,
236230
*columns,
237231
comment=description,
238-
schema=self.schema.name if self.apply_schema_to_tables else None,
239232
**optargs, # type: ignore[arg-type]
240233
)
241234

python/felis/tap_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def _load_yaml(self) -> None:
131131
self.schema_name = self.schema.name
132132

133133
self._metadata = MetaDataBuilder(
134-
self.schema,
135-
apply_schema_to_metadata=self.apply_schema_to_metadata,
136-
apply_schema_to_tables=self.apply_schema_to_metadata,
134+
self.schema, apply_schema_to_metadata=self.apply_schema_to_metadata
137135
).build()
138136

139137
logger.debug("Loaded TAP_SCHEMA '%s' from YAML resource", self.schema_name)

tests/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ def test_diff_database(self) -> None:
207207
db_url = f"sqlite:///{self.tmpdir}/tap_schema.sqlite3"
208208

209209
engine = create_engine(db_url)
210-
metadata_db = MetaDataBuilder(
211-
Schema.from_uri(test_diff1), apply_schema_to_metadata=False, apply_schema_to_tables=False
212-
).build()
210+
metadata_db = MetaDataBuilder(Schema.from_uri(test_diff1), apply_schema_to_metadata=False).build()
213211
metadata_db.create_all(engine)
214212

215213
runner = CliRunner()

tests/test_diff.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TestSchemaDiff(unittest.TestCase):
3434
def _diff(self, schema1, schema2):
3535
return SchemaDiff(schema1, schema2).diff
3636

37-
def test_schema_diff(self):
37+
def test_schema_diff(self) -> None:
3838
"""Test the comparison output generated by the SchemaDiff class."""
3939
# Two schemas with different values
4040
schema1 = dm.Schema(name="schema1", id="#schema1", version="1.2.3", description="Schema 1", tables=[])
@@ -192,7 +192,7 @@ def test_schema_diff(self):
192192
# Call formatted handler function
193193
FormattedSchemaDiff(schema1, schema2)._handle_dictionary_item_removed(diff["dictionary_item_removed"])
194194

195-
def test_index_diff(self):
195+
def test_index_diff(self) -> None:
196196
"""Test differences in indices between tables."""
197197
schema1 = dm.Schema(name="schema1", id="#schema1", version="1.2.3", description="Schema 1", tables=[])
198198
schema1.tables.append(dm.Table(name="table1", id="#table1", description="Table 1", columns=[]))
@@ -222,22 +222,22 @@ def test_index_diff(self):
222222
# Print formatted diff to make sure it works for these changes
223223
FormattedSchemaDiff(schema1, schema2).print()
224224

225-
def test_print(self):
225+
def test_print(self) -> None:
226226
schema1 = dm.Schema(name="schema1", id="#schema1", version="1.2.3", description="Schema 1", tables=[])
227227
schema2 = dm.Schema(name="schema2", id="#schema2", version="4.5.6", description="Schema 2", tables=[])
228228
SchemaDiff(schema1, schema2).print()
229229

230-
def test_formatted_print(self):
230+
def test_formatted_print(self) -> None:
231231
schema1 = dm.Schema(name="schema1", id="#schema1", version="1.2.3", description="Schema 1", tables=[])
232232
schema2 = dm.Schema(name="schema2", id="#schema2", version="4.5.6", description="Schema 2", tables=[])
233233
FormattedSchemaDiff(schema1, schema2).print()
234234

235-
def test_parse_deepdiff_path(self):
235+
def test_parse_deepdiff_path(self) -> None:
236236
path = "root['tables'][0]['columns'][0]['ivoa_ucd']"
237237
keys = FormattedSchemaDiff._parse_deepdiff_path(path)
238238
self.assertListEqual(keys, ["tables", 0, "columns", 0, "ivoa_ucd"])
239239

240-
def test_get_id_error(self):
240+
def test_get_id_error(self) -> None:
241241
id_dict = {"tables": [{"indexes": [{"columns": [{"name": "column1"}, {"name": "column2"}]}]}]}
242242
keys = ["tables", 0, "indexes", 0, "columns", 0]
243243
with self.assertRaises(ValueError):
@@ -247,7 +247,7 @@ def test_get_id_error(self):
247247
class TestDatabaseDiff(unittest.TestCase):
248248
"""Test the DatabaseDiff class."""
249249

250-
def test_database_diff(self):
250+
def test_database_diff(self) -> None:
251251
"""Test the comparison output generated by the DatabaseDiff class."""
252252
# Two tables with different columns
253253
schema1 = dm.Schema(name="schema1", id="#schema1", version="1.2.3", description="Schema 1", tables=[])
@@ -265,9 +265,7 @@ def test_database_diff(self):
265265
dm.Column(name="column2", datatype="string", length=256, id="#column2", description="Column 2")
266266
)
267267

268-
metadata_db = MetaDataBuilder(
269-
schema1, apply_schema_to_metadata=False, apply_schema_to_tables=False
270-
).build()
268+
metadata_db = MetaDataBuilder(schema1, apply_schema_to_metadata=False).build()
271269
engine = create_engine("sqlite:///:memory:")
272270
metadata_db.create_all(engine)
273271

tests/test_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_builder(self) -> None:
147147
builder matches the data in the Felis schema used to create it.
148148
"""
149149
sch = Schema.model_validate(self.yaml_data)
150-
bld = MetaDataBuilder(sch, apply_schema_to_tables=False, apply_schema_to_metadata=False)
150+
bld = MetaDataBuilder(sch, apply_schema_to_metadata=False)
151151
md = bld.build()
152152

153153
self.assertEqual(len(sch.tables), len(md.tables))

0 commit comments

Comments
 (0)