Only allow floats in LonLat (and not None, None).
[philipp/winterrodeln/wrpylib.git] / wrpylib / mwdb.py
1 """This module contains code to make the access of MediaWiki tables
2 easy. The module uses sqlalchemy to access the database.
3 """
4 from sqlalchemy import Table, Column, types
5
6
7 def page_table(metadata):
8     """Returns the sqlalchemy Table representing the "page" table in MediaWiki.
9     :param metadata: metadata = sqlalchemy.MetaData()
10     """
11     return Table(
12         "page", metadata,
13         Column("page_id", types.Integer, primary_key=True),
14         Column("page_namespace", types.Integer, nullable=False),
15         Column("page_title", types.String(255, convert_unicode='force'), nullable=False),
16         Column("page_restrictions", types.String, nullable=False),  # tinyblob NOT NULL
17         Column("page_is_redirect", types.Integer, nullable=False),
18         Column("page_is_new", types.Integer, nullable=False),
19         Column("page_random", types.Float, nullable=False),
20         Column("page_touched", types.String(14, convert_unicode='force'), nullable=False),
21         Column("page_latest", types.Integer, nullable=False),
22         Column("page_len", types.Integer, nullable=False),
23         Column("page_content_model", types.String(32, convert_unicode='force')),
24         Column("page_links_updated", types.String(14, convert_unicode='force')),
25         Column("page_lang", types.String(35, convert_unicode='force')),
26     )
27
28
29 def revision_table(metadata):
30     """Returns the sqlalchemy Table representing the "revision" table in MediaWiki.
31     :param metadata: metadata = sqlalchemy.MetaData()
32     """
33     return Table(
34         "revision", metadata,
35         Column("rev_id", types.Integer, nullable=False, primary_key=True),
36         Column("rev_page", types.Integer, nullable=False, primary_key=True),
37         Column("rev_text_id", types.Integer, nullable=False),
38         Column("rev_comment", types.String(convert_unicode='force'), nullable=False),  # tinyblob NOT NULL
39         Column("rev_user", types.Integer, nullable=False),
40         Column("rev_user_text", types.String(255, convert_unicode='force'), nullable=False),
41         Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False),
42         Column("rev_minor_edit", types.Integer, nullable=False),
43         Column("rev_deleted", types.Integer, nullable=False),
44         Column("rev_len", types.Integer, nullable=False),
45         Column("rev_parent_id", types.Integer, nullable=False),
46     )
47
48
49 def text_table(metadata):
50     """Returns the sqlalchemy Table representing the "text" table in MediaWiki.
51     :param metadata: metadata = sqlalchemy.MetaData()
52     """
53     return Table(
54         "text", metadata,
55         Column("old_id", types.Integer, primary_key=True),
56         Column("old_text", types.String(convert_unicode='force')),
57         Column("old_flags", types.String(convert_unicode='force')),
58     )
59
60
61 def user_table(metadata):
62     """Returns the sqlalchemy Table representing the "user" table in MediaWiki.
63     :param metadata: metadata = sqlalchemy.MetaData()
64     """
65     return Table(
66         'user', metadata,
67         Column("user_id", types.Integer, primary_key=True),
68         Column("user_name", types.String(255, convert_unicode='force'), nullable=False),
69         Column("user_real_name", types.String(255, convert_unicode='force'), nullable=False),
70         Column("user_password", types.UnicodeText, nullable=False),
71         # "user_newpassword"
72         # "user_newpass_time"
73         Column("user_email", types.String(convert_unicode='force'), nullable=False),
74         # "user_touched"
75         # "user_token"
76         # "user_email_authenticated"
77         # "user_email_token"
78         # "user_email_token_expires"
79         # "user_registration"
80         # "user_editcount"
81     )
82
83
84 def user_groups_table(metadata):
85     """
86     Returns the sqlalchemy Table representing the "user_groups" table in MediaWiki.
87
88     :param metadata: metadata = sqlalchemy.MetaData()
89     """
90     return Table(
91         'user_groups', metadata,
92         Column('ug_user', types.Integer, nullable=False, primary_key=True),
93         Column('ug_group', types.String(255, convert_unicode='force'), nullable=False, primary_key=True),
94         Column("ug_expiry", types.String(14, convert_unicode='force')),
95     )
96
97
98 def categorylinks_table(metadata):
99     """Returns the sqlalchemy Table representing the "categorylinks" table in MediaWiki.
100     :param metadata: metadata = sqlalchemy.MetaData()
101     """
102     return Table(
103         "categorylinks", metadata,
104         Column("cl_from", types.Integer, nullable=False, primary_key=True),
105         Column("cl_to", types.String(255, convert_unicode='force'), nullable=False, primary_key=True),
106         Column("cl_sortkey", types.String(230, convert_unicode='force'), nullable=False),
107         Column("cl_timestamp", types.DateTime, nullable=False),
108     )