Skip to content
Snippets Groups Projects
Commit 58bca5af authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Fix database migration when the database is empty

parent 9d2bdae1
No related branches found
No related tags found
No related merge requests found
......@@ -32,17 +32,18 @@ def upgrade():
conn = op.get_bind()
res = conn.execute("SELECT id FROM tag WHERE name = 'IOC';")
row = res.fetchone()
ioc_tag_id = row[0]
res.close()
res = conn.execute(
f"""SELECT interface.host_id FROM interface
INNER JOIN interfacetags ON interface.id = interfacetags.interface_id
WHERE interfacetags.tag_id = {ioc_tag_id};
"""
)
results = res.fetchall()
for result in results:
op.execute(host.update().where(host.c.id == result[0]).values(is_ioc=True))
if row is not None:
ioc_tag_id = row[0]
res.close()
res = conn.execute(
f"""SELECT interface.host_id FROM interface
INNER JOIN interfacetags ON interface.id = interfacetags.interface_id
WHERE interfacetags.tag_id = {ioc_tag_id};
"""
)
results = res.fetchall()
for result in results:
op.execute(host.update().where(host.c.id == result[0]).values(is_ioc=True))
op.drop_table("interfacetags")
op.drop_table("tag")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment