Skip to content

Commit 5a18618

Browse files
authored
include table and column comments
1 parent 406d6ab commit 5a18618

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

cbl_migrator/migrator.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def fill_table(o_engine_conn, d_engine_conn, table_name, chunk_size):
5454
except Exception as e:
5555
logger.error(f"Need to create {table_name} table before filling it", e)
5656
raise Exception(f"Need to create {table_name} table before filling it")
57-
57+
5858
dpk = [c for c in d_table.primary_key.columns][0]
5959
count = o_engine.execute(select([func.count(pk)])).scalar()
6060
d_count = d_engine.execute(select([func.count(dpk)])).scalar()
@@ -67,7 +67,7 @@ def fill_table(o_engine_conn, d_engine_conn, table_name, chunk_size):
6767
elif count != d_count and d_count != 0:
6868
q = select([d_table]).order_by(dpk.desc()).limit(1)
6969
res = d_engine.execute(q)
70-
next_id = res.fetchone().__getitem__(dpk.name)
70+
last_id = res.fetchone().__getitem__(dpk.name)
7171
first_it = False
7272

7373
# table has a composite pk (usualy a bad design choice).
@@ -99,13 +99,13 @@ def fill_table(o_engine_conn, d_engine_conn, table_name, chunk_size):
9999
while True:
100100
q = select([table]).order_by(pk).limit(chunk_size)
101101
if not first_it:
102-
q = q.where(pk > next_id)
102+
q = q.where(pk > last_id)
103103
else:
104104
first_it = False
105105
res = o_engine.execute(q)
106106
data = res.fetchall()
107107
if len(data):
108-
next_id = data[-1].__getitem__(pk.name)
108+
last_id = data[-1].__getitem__(pk.name)
109109
d_engine.execute(
110110
table.insert(),
111111
[
@@ -262,16 +262,12 @@ def __copy_schema(self):
262262

263263
table.indexes = set()
264264

265-
# TODO: Hacky. Fails when reflecting column/table comments so removing it.
266265
new_metadata_cols = ColumnCollection()
267266
for col in table._columns:
268-
col.comment = None
269267
col = self.__fix_column_type(col, d_engine.name)
270-
# be sure that no column has auto-increment
271268
col.autoincrement = False
272269
new_metadata_cols.add(col)
273270
table.columns = new_metadata_cols.as_immutable()
274-
table.comment = None
275271
new_metadata_tables[table_name] = table
276272
metadata.tables = immutabledict(new_metadata_tables)
277273
metadata.create_all(d_engine)

cbl_migrator/test/schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
Base = declarative_base()
66

77
class Compound(Base):
8-
8+
"""
9+
Non redundant list of compounds/biotherapeutics with associated identifiers
10+
"""
911
__tablename__ = 'compound'
1012

11-
cid = Column(Integer, primary_key=True)
13+
cid = Column(Integer, primary_key=True, comment="Internal Primary Key for the molecule")
1214
structure_type = Column(Integer, CheckConstraint("structure_type in ('NONE','MOL','SEQ','BOTH')"))
1315
compound_name = Column(String(255), index=True)
1416

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
if __name__ == '__main__':
44
setup(
55
name='cbl_migrator',
6-
version='0.1.3',
6+
version='0.1.4',
77
author='Eloy Félix',
88
author_email='eloyfelix@gmail.com',
99
description='Migrates Oracle dbs to PostgreSQL, MySQL and Sqlite',
@@ -12,7 +12,7 @@
1212
packages=['cbl_migrator'],
1313
long_description=open('README.md', encoding='utf-8').read(),
1414
long_description_content_type='text/markdown',
15-
install_requires=['SQLAlchemy>=1.2'],
15+
install_requires=['SQLAlchemy>=1.3'],
1616
tests_require=['exrex'],
1717
classifiers=['Development Status :: 2 - Pre-Alpha',
1818
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)