MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / fk

Method fk

lib/sqlalchemy/testing/suite/test_ddl.py:238–282  ·  view source on GitHub ↗
(self, metadata, connection)

Source from the content-addressed store, hash-verified

236 __sparse_driver_backend__ = True
237
238 def fk(self, metadata, connection):
239 convention = {
240 "fk": "foreign_key_%(table_name)s_"
241 "%(column_0_N_name)s_"
242 "%(referred_table_name)s_"
243 + (
244 "_".join(
245 "".join(random.choice("abcdef") for j in range(20))
246 for i in range(10)
247 )
248 ),
249 }
250 metadata.naming_convention = convention
251
252 Table(
253 "a_things_with_stuff",
254 metadata,
255 Column("id_long_column_name", Integer, primary_key=True),
256 test_needs_fk=True,
257 )
258
259 cons = ForeignKeyConstraint(
260 ["aid"], ["a_things_with_stuff.id_long_column_name"]
261 )
262 Table(
263 "b_related_things_of_value",
264 metadata,
265 Column(
266 "aid",
267 ),
268 cons,
269 test_needs_fk=True,
270 )
271 actual_name = cons.name
272
273 metadata.create_all(connection)
274
275 if testing.requires.foreign_key_constraint_name_reflection.enabled:
276 insp = inspect(connection)
277 fks = insp.get_foreign_keys("b_related_things_of_value")
278 reflected_name = fks[0]["name"]
279
280 return actual_name, reflected_name
281 else:
282 return actual_name, None
283
284 def pk(self, metadata, connection):
285 convention = {

Callers

nothing calls this directly

Calls 7

inspectFunction · 0.90
create_allMethod · 0.80
TableFunction · 0.50
ColumnFunction · 0.50
joinMethod · 0.45
get_foreign_keysMethod · 0.45

Tested by

no test coverage detected