Reputation: 103
Is there a way to reuse the column definitions across all tables to avoid mix types between tables.
It's a common issue on DW to have the same column in many tables. Using SqlAlchemy Core.
t_teachers = Table(
'teachers', metadata,
Column('teacher_uid', String(20), primary_key=True),
Column('first_name', String(50)),
Column('last_name', String(50)),
)
t_students = Table(
'students', metadata,
Column('student_uid', String(20), primary_key=True),
Column('first_name', String(50)),
Column('last_name', String(50)),
)
exams = Table(
'exams', metadata,
Column('exam_id', String(20), primary_key=True),
Column('teacher_uid', String(20), ForeignKey('teachers.teacher_uid'), nullable=False),
Column('student_uid', String(20), ForeignKey('students.student_uid'), nullable=False),
Column('points', Integer),
)
exam_marts = Table(
'exams_marts', metadata,
Column('teacher_first_name', String(50)),
Column('teacher_last_name', String(50)),
Column('student_first_name', String(50)),
Column('student_last_name', String(50)),
Column('exam_name', String(50)),
Column('points', Integer),
)
Upvotes: 1
Views: 841
Reputation: 331
Something like this?
def mixin_factory():
return (sa.Column("created", sa.Date),)
tablename_table = sa.Table(
"tablename",
metadata,
*mixin_factory()
)
Upvotes: 2