Add an is_expired column to the model

You should delete your database and let the software recreate it after
this commit. Alternatively, add the `is_expired` column to the flats
table.
This commit is contained in:
Julien Wajsberg 2018-09-28 19:22:27 +02:00 committed by Phyks (Lucas Verney)
parent dc9abadf12
commit e8c28a4a91
2 changed files with 11 additions and 1 deletions

View File

@ -155,6 +155,11 @@ def import_and_filter(config, load_from_db=False):
flatten_flats_by_status[status].extend(flats_list)
with get_session() as session:
# Set is_expired to true for all existing flats.
# This will be set back to false if we find them during importing.
for flat in session.query(flat_model.Flat).all():
flat.is_expired = True;
for status, flats_list in flatten_flats_by_status.items():
# Build SQLAlchemy Flat model objects for every available flat
flats_objects = {
@ -178,6 +183,10 @@ def import_and_filter(config, load_from_db=False):
)
else:
flat_object.status = each.status
# Every flat we fetched isn't expired
flat_object.is_expired = False
# For each flat already in the db, merge it (UPDATE)
# instead of adding it
session.merge(flats_objects.pop(each.id))

View File

@ -11,7 +11,7 @@ import enum
import arrow
from sqlalchemy import (
Column, DateTime, Enum, Float, SmallInteger, String, Text, inspect
Boolean, Column, DateTime, Enum, Float, SmallInteger, String, Text, inspect
)
from sqlalchemy.orm import validates
@ -83,6 +83,7 @@ class Flat(BASE):
merged_ids = Column(MagicJSON)
notes = Column(Text)
notation = Column(SmallInteger, default=0)
is_expired = Column(Boolean, default=False)
# Flatisfy data
# TODO: Should be in another table with relationships