mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 12:54:15 +02:00
Black
This commit is contained in:
parent
f35e4e6662
commit
093c3e66db
1 changed files with 2 additions and 7 deletions
|
|
@ -217,7 +217,6 @@ def add_foreign_key(path, table, column, other_table, other_column):
|
||||||
raise click.ClickException(e)
|
raise click.ClickException(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command(name="index-foreign-keys")
|
@cli.command(name="index-foreign-keys")
|
||||||
@click.argument(
|
@click.argument(
|
||||||
"path",
|
"path",
|
||||||
|
|
@ -231,14 +230,10 @@ def index_foreign_keys(path):
|
||||||
db = sqlite_utils.Database(path)
|
db = sqlite_utils.Database(path)
|
||||||
for table_name in db.table_names():
|
for table_name in db.table_names():
|
||||||
table = db[table_name]
|
table = db[table_name]
|
||||||
existing_indexes = {
|
existing_indexes = {i.columns[0] for i in table.indexes if len(i.columns) == 1}
|
||||||
i.columns[0] for i in table.indexes if len(i.columns) == 1
|
|
||||||
}
|
|
||||||
for fk in table.foreign_keys:
|
for fk in table.foreign_keys:
|
||||||
if fk.column not in existing_indexes:
|
if fk.column not in existing_indexes:
|
||||||
print("Creating index on {}.{}".format(
|
print("Creating index on {}.{}".format(table_name, fk.column))
|
||||||
table_name, fk.column
|
|
||||||
))
|
|
||||||
table.create_index([fk.column])
|
table.create_index([fk.column])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue