| 1277 | def go(allow_partial_pks): |
| 1278 | |
| 1279 | class Section(decl_base): |
| 1280 | __tablename__ = "sections" |
| 1281 | year = Column(Integer, primary_key=True) |
| 1282 | idx = Column(Integer, primary_key=True) |
| 1283 | parent_idx = Column(Integer) |
| 1284 | |
| 1285 | if not allow_partial_pks: |
| 1286 | __mapper_args__ = {"allow_partial_pks": False} |
| 1287 | |
| 1288 | ForeignKeyConstraint((year, parent_idx), (year, idx)) |
| 1289 | |
| 1290 | parent = relationship( |
| 1291 | "Section", |
| 1292 | primaryjoin=and_( |
| 1293 | year == remote(year), |
| 1294 | foreign(parent_idx) == remote(idx), |
| 1295 | ), |
| 1296 | ) |
| 1297 | |
| 1298 | decl_base.metadata.create_all(connection) |
| 1299 | connection.commit() |