2 import sqlalchemy as sa
3 from sqlalchemy import orm, schema, types
4 from wradmin.model import meta
7 def init_model(engine):
8 """Call me before using any of the tables or classes in the model"""
9 meta.Session.configure(bind=engine)
13 # Current table definition
15 # - version 1.3 (no changes)
16 wrreport_table = sa.Table("wrreport", meta.metadata,
17 sa.Column("id", types.Integer, primary_key=True),
18 sa.Column("page_id", types.Integer, schema.ForeignKey('wrsleddingcache.page_id')),
19 sa.Column("page_title", types.Unicode(255), nullable=False),
20 sa.Column("date_report", types.Date),
21 sa.Column("date_entry", types.DateTime, nullable=False),
22 sa.Column("date_invalid", types.DateTime),
23 sa.Column("condition", types.Integer),
24 sa.Column("description", types.Unicode),
25 sa.Column("author_name", types.Unicode(30)),
26 sa.Column("author_ip", types.Unicode(15)),
27 sa.Column("author_userid", types.Integer),
28 sa.Column("author_username", types.Unicode(30)),
29 sa.Column("delete_date", types.DateTime),
30 sa.Column("delete_person_name", types.Unicode(30)),
31 sa.Column("delete_person_ip", types.Unicode(15)),
32 sa.Column("delete_person_userid", types.Integer),
33 sa.Column("delete_person_username", types.Unicode(30)),
34 sa.Column("delete_reason_public", types.Unicode),
38 # Old table definition
40 wrsleddingcache1_2_table = sa.Table("wrsleddingcache1_2", meta.metadata,
41 sa.Column("page_id", types.Integer, primary_key=True),
42 sa.Column("page_title", types.Unicode(255)),
43 sa.Column("length", types.Integer),
44 sa.Column("walktime", types.Integer),
45 sa.Column("height_top", types.Integer),
46 sa.Column("height_bottom", types.Integer),
47 sa.Column("walkup_separate", types.Boolean),
48 sa.Column("lift", types.Boolean),
49 sa.Column("night_light", types.Boolean),
50 sa.Column("sledge_rental", types.Boolean),
51 sa.Column("public_transport", types.Boolean),
52 sa.Column("image", types.Unicode(255)),
53 sa.Column("position_latitude", types.Float),
54 sa.Column("position_longitude", types.Float),
55 sa.Column("information", types.Unicode(255)),
56 sa.Column("forum_id", types.Integer),
57 sa.Column("under_construction", types.Boolean),
58 sa.Column("show_in_overview", types.Boolean),
62 # Current table definition
63 # - version 1.3 (changes made from version 1.2)
64 wrsleddingcache_table = sa.Table("wrsleddingcache", meta.metadata,
65 sa.Column("page_id", types.Integer, primary_key=True),
66 sa.Column("page_title", types.Unicode(255)),
67 sa.Column("position_latitude", types.Float),
68 sa.Column("position_longitude", types.Float),
69 sa.Column("top_latitude", types.Float),
70 sa.Column("top_longitude", types.Float),
71 sa.Column("top_elevation", types.Integer),
72 sa.Column("bottom_latitude", types.Float),
73 sa.Column("bottom_longitude", types.Float),
74 sa.Column("bottom_elevation", types.Integer),
75 sa.Column("length", types.Integer),
76 sa.Column("difficulty", types.Integer),
77 sa.Column("avalanches", types.Integer),
78 sa.Column("operator", types.Unicode(255)),
79 sa.Column("public_transport", types.Integer),
80 sa.Column("walkup_time", types.Integer),
81 sa.Column("walkup_separate", types.Float),
82 sa.Column("walkup_separate_comment", types.Unicode(255)),
83 sa.Column("lift", types.Boolean),
84 sa.Column("lift_details", types.Unicode(255)),
85 sa.Column("night_light", types.Float),
86 sa.Column("night_light_days", types.Integer),
87 sa.Column("night_light_days_comment", types.Unicode(255)),
88 sa.Column("sled_rental", types.Boolean),
89 sa.Column("cachet", types.Unicode(255)),
90 sa.Column("information_web", types.Unicode(255)),
91 sa.Column("information_phone", types.Unicode(255)),
92 sa.Column("image", types.Unicode(255)),
93 sa.Column("show_in_overview", types.Boolean),
94 sa.Column("forum_id", types.Integer),
95 sa.Column("under_construction", types.Boolean),
99 # Old table definition
101 wrinncache_table1_2 = sa.Table("wrinncache1_2", meta.metadata,
102 sa.Column("page_id", types.Integer, primary_key=True),
103 sa.Column("page_title", types.Unicode(255)),
104 sa.Column("height", types.Integer),
105 sa.Column("phone", types.Unicode(30)),
106 sa.Column("mobile_phone", types.Unicode(30)),
107 sa.Column("email", types.Unicode(255)),
108 sa.Column("homepage", types.Unicode(255)),
109 sa.Column("smoker_area", types.Boolean),
110 sa.Column("nonsmoker_area", types.Boolean),
111 sa.Column("image", types.Unicode(255)),
112 sa.Column("position_latitude", types.Float),
113 sa.Column("position_longitude", types.Float),
114 sa.Column("under_construction", types.Boolean),
118 # Current table definition
119 # - version 1.3 (changes made from version 1.2)
120 wrinncache_table = sa.Table("wrinncache", meta.metadata,
121 sa.Column("page_id", types.Integer, primary_key=True),
122 sa.Column("page_title", types.Unicode(255)),
123 sa.Column("height", types.Integer),
124 sa.Column("phone", types.Unicode(30)),
125 sa.Column("mobile_phone", types.Unicode(30)),
126 sa.Column("email", types.Unicode(255)),
127 sa.Column("homepage", types.Unicode(255)),
128 sa.Column("smoker_area", types.Boolean),
129 sa.Column("nonsmoker_area", types.Boolean),
130 sa.Column("image", types.Unicode(255)),
131 sa.Column("position_latitude", types.Float),
132 sa.Column("position_longitude", types.Float),
133 sa.Column("under_construction", types.Boolean),
137 page_table = sa.Table("page", meta.metadata,
138 sa.Column("page_id", types.Integer, primary_key=True),
139 sa.Column("page_namespace", types.Integer, nullable=False),
140 sa.Column("page_title", types.Unicode(255), nullable=False),
141 sa.Column("page_restrictions", types.Unicode, nullable=False),
142 sa.Column("page_counter", types.Integer, nullable=False),
143 sa.Column("page_is_redirect", types.Integer, nullable=False),
144 sa.Column("page_is_new", types.Integer, nullable=False),
145 sa.Column("page_random", types.Float, nullable=False),
146 sa.Column("page_touched", types.Unicode(14), nullable=False),
147 sa.Column("page_latest", types.Integer, nullable=False),
148 sa.Column("page_len", types.Integer, nullable=False),
152 revision_table = sa.Table("revision", meta.metadata,
153 sa.Column("rev_id", types.Integer, nullable=False, primary_key=True),
154 sa.Column("rev_page", types.Integer, nullable=False, primary_key=True),
155 sa.Column("rev_text_id", types.Integer, nullable=False),
156 sa.Column("rev_comment", types.Unicode),
157 sa.Column("rev_user", types.Integer, nullable=False),
158 sa.Column("rev_user_text", types.Unicode(255), nullable=False),
159 sa.Column("rev_timestamp", types.Unicode(14), nullable=False),
160 sa.Column("rev_minor_edit", types.Integer, nullable=False),
161 sa.Column("rev_deleted", types.Integer, nullable=False),
162 sa.Column("rev_len", types.Integer, nullable=False),
163 sa.Column("rev_parent_id", types.Integer, nullable=False),
167 text_table = sa.Table("text", meta.metadata,
168 sa.Column("old_id", types.Integer, primary_key=True),
169 sa.Column("old_text", types.Unicode),
170 sa.Column("old_flags", types.Unicode),
174 categorylinks_table = sa.Table("categorylinks", meta.metadata,
175 sa.Column("cl_from", types.Integer, nullable=False, primary_key=True),
176 sa.Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
177 sa.Column("cl_sortkey", types.Unicode, nullable=False),
178 sa.Column("cl_timestamp", types.DateTime, nullable=False),
182 class WrReport(object):
186 # Old version (not mapped)
187 class WrSleddingCache1_2(object):
191 class WrSleddingCache(object):
195 # Old version (not mapped)
196 class WrInnCache1_2(object):
200 class WrInnCache(object):
209 orm.mapper(WrReport, wrreport_table)
210 # We could add a relation but we don't need it yet:
211 # orm.mapper(WrSleddingCache, wrsleddingcache_table, properties = {'reports': orm.relation(WrReport, backref='sledding')})
212 orm.mapper(WrSleddingCache, wrsleddingcache_table)
213 orm.mapper(WrInnCache, wrinncache_table)