mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-14 12:34:10 +02:00
Ability to add a column that is a foreign key reference
Python API:
db["dogs"].add_column("species_id", fk="species")
# or
db["dogs"].add_column("species_id", fk="species", fk_col="ref")
CLI:
$ sqlite-utils add-column mydb.db dogs species_id --fk species
# or
$ sqlite-utils add-column mydb.db dogs species_id --fk species --fk-col ref
Closes #16
This commit is contained in:
parent
00c5a49a87
commit
50e2f94b58
6 changed files with 118 additions and 6 deletions
|
|
@ -169,10 +169,12 @@ def optimize(path, no_vacuum):
|
|||
),
|
||||
required=False,
|
||||
)
|
||||
def add_column(path, table, col_name, col_type):
|
||||
@click.option("--fk", type=str, required=False)
|
||||
@click.option("--fk-col", type=str, required=False)
|
||||
def add_column(path, table, col_name, col_type, fk, fk_col):
|
||||
"Add a column to the specified table"
|
||||
db = sqlite_utils.Database(path)
|
||||
db[table].add_column(col_name, col_type)
|
||||
db[table].add_column(col_name, col_type, fk=fk, fk_col=fk_col)
|
||||
|
||||
|
||||
@cli.command(name="add-foreign-key")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue