Revision 3006
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1020 | 1020 |
if sql_gen.index_col(col) != None: return # already has index col |
1021 | 1021 |
|
1022 | 1022 |
new_col = sql_gen.suffixed_col(col, suffix) |
1023 |
new_typed_col = sql_gen.TypedCol(new_col.name, db.col_info(col).type) |
|
1024 | 1023 |
|
1025 |
add_col(db, col.table, new_typed_col) |
|
1024 |
# Add column |
|
1025 |
while True: |
|
1026 |
new_typed_col = sql_gen.TypedCol(new_col.name, db.col_info(col).type) |
|
1027 |
try: |
|
1028 |
add_col(db, col.table, new_typed_col, |
|
1029 |
log_ignore_excs=(DuplicateException,)) |
|
1030 |
break |
|
1031 |
except DuplicateException: |
|
1032 |
new_col.name = next_version(new_col.name) |
|
1033 |
# try again with next version of name |
|
1034 |
|
|
1026 | 1035 |
update(db, col.table, [(new_col, expr)]) |
1027 | 1036 |
if not nullable: add_not_null(db, new_col) |
1028 | 1037 |
add_index(db, new_col) |
... | ... | |
1056 | 1065 |
|
1057 | 1066 |
def add_col(db, table, col, **kw_args): |
1058 | 1067 |
assert isinstance(col, sql_gen.TypedCol) |
1059 |
try: run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN '
|
|
1068 |
run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN ' |
|
1060 | 1069 |
+col.to_str(db), recover=True, cacheable=True, **kw_args) |
1061 |
except DuplicateException: pass # column already existed |
|
1062 | 1070 |
|
1063 | 1071 |
row_num_typed_col = sql_gen.TypedCol(row_num_col, 'serial', nullable=False, |
1064 | 1072 |
constraints='PRIMARY KEY') |
Also available in: Unified diff
sql.py: add_col(): Don't ignore already-existing columns because sometimes name truncation causes collisions, requiring the caller to version the name. add_index_col(): Version the column name to avoid collisions.