-
Notifications
You must be signed in to change notification settings - Fork 5
/
models.py
61 lines (45 loc) · 1.6 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from app import db
from sqlalchemy import func
from sqlalchemy.dialects.postgresql import JSON
class EsriServer(db.Model):
__tablename__ = 'servers'
id = db.Column(db.Integer, primary_key=True)
created_at = db.Column(db.DateTime(), default=func.now())
updated_at = db.Column(db.DateTime(), onupdate=func.now())
job_id = db.Column(db.String(), nullable=True)
url = db.Column(db.String(), unique=True)
status = db.Column(db.String(), default='added')
last_crawled = db.Column(db.DateTime(), nullable=True)
def __repr__(self):
return '<EsriServer {}: {}>'.format(self.id, self.url)
class Service(db.Model):
__tablename__ = 'services'
id = db.Column(db.Integer, primary_key=True)
created_at = db.Column(db.DateTime(), default=func.now())
server_id = db.Column(db.Integer, db.ForeignKey('servers.id'))
service_data = db.Column(JSON())
name = db.Column(db.String())
service_type = db.Column(db.String())
server = db.relationship(
EsriServer,
backref=db.backref(
'services',
lazy='dynamic',
cascade='delete,all',
)
)
class Layer(db.Model):
__tablename__ = 'layers'
id = db.Column(db.Integer, primary_key=True)
created_at = db.Column(db.DateTime(), default=func.now())
service_id = db.Column(db.Integer, db.ForeignKey('services.id'))
layer_data = db.Column(JSON())
name = db.Column(db.String())
service = db.relationship(
Service,
backref=db.backref(
'layers',
lazy='dynamic',
cascade='delete,all',
)
)