Added 'foto' and 'verleih' as possible point types.
[philipp/winterrodeln/wrpylib.git] / wrpylib / mwdb.py
1 #!/usr/bin/python2.7
2 # -*- coding: iso-8859-15 -*-
3 # $Id$
4 # $HeadURL$
5 """This module contains code to make the access of MediaWiki tables
6 easy. The module uses sqlalchemy to access the database.
7 """
8 from sqlalchemy import Table, Column, types
9
10
11 def page_table(metadata):
12     """Returns the sqlalchemy Table representing the "page" table in MediaWiki.
13     :param metadata: metadata = sqlalchemy.MetaData()
14     """
15     return Table("page", metadata,
16     Column("page_id", types.Integer, primary_key=True),
17     Column("page_namespace", types.Integer, nullable=False),
18     Column("page_title", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
19     Column("page_restrictions", types.String, nullable=False), # tinyblob NOT NULL
20     Column("page_counter", types.Integer, nullable=False),
21     Column("page_is_redirect", types.Integer, nullable=False),
22     Column("page_is_new", types.Integer, nullable=False),
23     Column("page_random", types.Float, nullable=False),
24     Column("page_touched", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
25     Column("page_latest", types.Integer, nullable=False),
26     Column("page_len", types.Integer, nullable=False),
27     )
28
29
30 def revision_table(metadata):
31     """Returns the sqlalchemy Table representing the "revision" table in MediaWiki.
32     :param metadata: metadata = sqlalchemy.MetaData()
33     """
34     return Table("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.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
41     Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
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("text", metadata,
54     Column("old_id", types.Integer, primary_key=True),
55     Column("old_text", types.String(convert_unicode='force')), # mediumblob NOT NULL
56     Column("old_flags", types.String(convert_unicode='force')), # tinyblob NOT NULL
57     )
58
59
60 def user_table(metadata):
61     """Returns the sqlalchemy Table representing the "user" table in MediaWiki.
62     :param metadata: metadata = sqlalchemy.MetaData()
63     """
64     return Table('user', metadata,
65     Column("user_id", types.Integer, primary_key=True),
66     Column("user_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
67     Column("user_real_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
68     # "user_password"
69     # "user_newpassword"
70     # "user_newpass_time"
71     Column("user_email", types.Unicode, nullable=False), # tinytext NOT NULL
72     # "user_touched"
73     # "user_token"
74     # "user_email_authenticated"
75     # "user_email_token"
76     # "user_email_token_expires"
77     # "user_registration"
78     # "user_editcount"
79     )
80
81
82 def categorylinks_table(metadata):
83     """Returns the sqlalchemy Table representing the "categorylinks" table in MediaWiki.
84     :param metadata: metadata = sqlalchemy.MetaData()
85     """
86     return Table("categorylinks", metadata,
87     Column("cl_from", types.Integer, nullable=False, primary_key=True),
88     Column("cl_to", types.Unicode(255), nullable=False, primary_key=True), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
89     Column("cl_sortkey", types.String(convert_unicode='force'), nullable=False), # varbinary(230) NOT NULL
90     Column("cl_timestamp", types.DateTime, nullable=False),
91     )
92