From 7aaa18cf24df9d90ac33f6fe0b1e0f54107569a2 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 20 Jun 2021 15:01:23 +0200 Subject: [PATCH] Add Changeset class --- matcher/model.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index 21d4249..ffbe28d 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -1,8 +1,8 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import ForeignKey, Column -from sqlalchemy.orm import relationship, column_property, deferred +from sqlalchemy.orm import relationship, column_property, deferred, backref from sqlalchemy import func -from sqlalchemy.types import Integer, String, Float, Boolean, DateTime, Text +from sqlalchemy.types import Integer, String, Float, Boolean, DateTime, Text, BigInteger from sqlalchemy.dialects import postgresql from sqlalchemy.sql.expression import cast from sqlalchemy.ext.hybrid import hybrid_property @@ -20,6 +20,10 @@ Base.query = session.query_property() re_point = re.compile(r'^POINT\((.+) (.+)\)$') +osm_type_enum = postgresql.ENUM('node', 'way', 'relation', + name='osm_type_enum', + metadata=Base.metadata) + class Item(Base): __tablename__ = "item" item_id = Column(Integer, primary_key=True, autoincrement=False) @@ -295,3 +299,32 @@ class User(Base, UserMixin): def is_active(self): return self.active + + +class Changeset(Base): + __tablename__ = 'changeset' + id = Column(BigInteger, primary_key=True) + created = Column(DateTime) + comment = Column(String) + user_id = Column(Integer, ForeignKey(User.id)) + update_count = Column(Integer, nullable=False) + + user = relationship('User', + backref=backref('changesets', + lazy='dynamic', + order_by='Changeset.created.desc()')) + + +class ChangesetEdit(Base): + __tablename__ = 'changeset_edit' + + changeset_id = Column(BigInteger, + ForeignKey('changeset.id'), + primary_key=True) + item_id = Column(Integer, primary_key=True) + osm_id = Column(BigInteger, primary_key=True) + osm_type = Column(osm_type_enum, primary_key=True) + saved = Column(DateTime, default=now_utc(), nullable=False) + + changeset = relationship('Changeset', + backref=backref('edits', lazy='dynamic'))