mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
add-column --ignore option, refs #450
This commit is contained in:
parent
2c77f4467e
commit
5fa823f03f
3 changed files with 35 additions and 4 deletions
|
|
@ -418,9 +418,22 @@ def dump(path, load_extension):
|
|||
required=False,
|
||||
help="Add NOT NULL DEFAULT 'TEXT' constraint",
|
||||
)
|
||||
@click.option(
|
||||
"--ignore",
|
||||
is_flag=True,
|
||||
help="If column already exists, do nothing",
|
||||
)
|
||||
@load_extension_option
|
||||
def add_column(
|
||||
path, table, col_name, col_type, fk, fk_col, not_null_default, load_extension
|
||||
path,
|
||||
table,
|
||||
col_name,
|
||||
col_type,
|
||||
fk,
|
||||
fk_col,
|
||||
not_null_default,
|
||||
ignore,
|
||||
load_extension,
|
||||
):
|
||||
"""Add a column to the specified table
|
||||
|
||||
|
|
@ -431,9 +444,13 @@ def add_column(
|
|||
"""
|
||||
db = sqlite_utils.Database(path)
|
||||
_load_extensions(db, load_extension)
|
||||
db[table].add_column(
|
||||
col_name, col_type, fk=fk, fk_col=fk_col, not_null_default=not_null_default
|
||||
)
|
||||
try:
|
||||
db[table].add_column(
|
||||
col_name, col_type, fk=fk, fk_col=fk_col, not_null_default=not_null_default
|
||||
)
|
||||
except OperationalError as ex:
|
||||
if not ignore:
|
||||
raise click.ClickException(str(ex))
|
||||
|
||||
|
||||
@cli.command(name="add-foreign-key")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue