Skip to content

Commit 47f2ccc

Browse files
committed
ENH: rename ignorefk to ignore_cols
1 parent 146b1ed commit 47f2ccc

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ What's different:
99
* Flask-SQLAlchemy columns are used (e.g. `db.Integer`).
1010
* Metadata is only implicit in tables
1111
* Defaults to generating backrefs in relationships. `--nobackref` still included as option in case backrefs are not wanted.
12-
* Naming of backrefs is the class name is snake_case (as opposed to CamelCase) and is pluralized if it's Many-to-One or Many-to-Many using <a href="https://pypi.python.org/pypi/inflect">inflect</a>.
12+
* Naming of backrefs is class name in snake_case (as opposed to CamelCase) and is pluralized if it's Many-to-One or Many-to-Many using <a href="https://pypi.python.org/pypi/inflect">inflect</a>.
1313
* Generate explicit primary joins. I deal with pretty complicated tables that need explicit primary joins.
1414
* If column has a server_default set it to `FetchValue()` instead of trying to determine what that value is. Original code did not set the right server defaults in my set up.
15-
* `--ignorefk` ignores special name columns (e.g. id, inserted, updated) when generating association tables. Original code requires all columns to be foreign keys in order to generate association table. Example: `--ignorefk id,inserted,updated`.
15+
* `--ignore-cols` ignores special columns (e.g. id, inserted, updated) when generating association tables. Original code requires all columns to be foreign keys in order to generate association table. Example: `--ignore-cols id,inserted,updated`.

sqlacodegen/codegen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class CodeGenerator(object):
527527

528528
def __init__(self, metadata, noindexes=False, noconstraints=False,
529529
nojoined=False, noinflect=False, nobackrefs=False,
530-
flask=False, fkcols=None):
530+
flask=False, ignore_cols=None):
531531
super(CodeGenerator, self).__init__()
532532

533533
if noinflect:
@@ -537,7 +537,7 @@ def __init__(self, metadata, noindexes=False, noconstraints=False,
537537
inflect_engine = inflect.engine()
538538

539539
# exclude these column names from consideration when generating association tables
540-
_special_columns = fkcols or []
540+
_ignore_columns = ignore_cols or []
541541

542542
self.flask = flask
543543
if not self.flask:
@@ -551,7 +551,7 @@ def __init__(self, metadata, noindexes=False, noconstraints=False,
551551
# Link tables have exactly two foreign key constraints and all columns are involved in them
552552
# except for special columns like id, inserted, and updated
553553
fk_constraints = [constr for constr in table.constraints if isinstance(constr, ForeignKeyConstraint)]
554-
if len(fk_constraints) == 2 and all(col.foreign_keys for col in table.columns if col.name not in _special_columns):
554+
if len(fk_constraints) == 2 and all(col.foreign_keys for col in table.columns if col.name not in _ignore_columns):
555555
association_tables.add(table.name)
556556
tablename = sorted(fk_constraints, key=_get_constraint_sort_key)[0].elements[0].column.table.name
557557
links[tablename].append(table)

sqlacodegen/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def main():
3636
parser.add_argument('--outfile', help='file to write output to (default: stdout)')
3737
parser.add_argument('--nobackrefs', action='store_true', help="don't include backrefs")
3838
parser.add_argument('--flask', action='store_true', help="use Flask-SQLAlchemy columns")
39-
parser.add_argument('--ignorefk', help="Don't check fk constraints on specified columns (comma-separated)")
40-
# parser.add_argument('--outfile', type=argparse.FileType('w'), default=sys.stdout,
41-
# help='file to write output to (default: stdout)')
39+
parser.add_argument('--ignore-cols', help="Don't check fk constraints on specified columns (comma-separated)")
4240
args = parser.parse_args()
4341

4442
if args.version:
@@ -53,10 +51,10 @@ def main():
5351
import_dialect_specificities(engine)
5452
metadata = MetaData(engine)
5553
tables = args.tables.split(',') if args.tables else None
56-
fkcols = args.ignorefk.split(',') if args.ignorefk else None
54+
ignore_cols = args.ignore_cols.split(',') if args.ignore_cols else None
5755
metadata.reflect(engine, args.schema, not args.noviews, tables)
5856
outfile = codecs.open(args.outfile, 'w', encoding='utf-8') if args.outfile else sys.stdout
5957
generator = CodeGenerator(metadata, args.noindexes, args.noconstraints,
6058
args.nojoined, args.noinflect, args.nobackrefs,
61-
args.flask, fkcols)
59+
args.flask, ignore_cols)
6260
generator.render(outfile)

0 commit comments

Comments
 (0)