1 """This module contains code to make the access of MediaWiki tables
2 easy. The module uses sqlalchemy to access the database.
4 from sqlalchemy import Table, Column, types
7 def page_table(metadata):
8 """Returns the sqlalchemy Table representing the "page" table in MediaWiki.
9 :param metadata: metadata = sqlalchemy.MetaData()
11 return Table("page", metadata,
12 Column("page_id", types.Integer, primary_key=True),
13 Column("page_namespace", types.Integer, nullable=False),
14 Column("page_title", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
15 Column("page_restrictions", types.String, nullable=False), # tinyblob NOT NULL
16 Column("page_is_redirect", types.Integer, nullable=False),
17 Column("page_is_new", types.Integer, nullable=False),
18 Column("page_random", types.Float, nullable=False),
19 Column("page_touched", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
20 Column("page_latest", types.Integer, nullable=False),
21 Column("page_len", types.Integer, nullable=False),
22 Column("page_content_model", types.String(32, convert_unicode='force')),
23 Column("page_links_updated", types.String(14, convert_unicode='force')),
24 Column("page_lang", types.String(35, convert_unicode='force')),
28 def revision_table(metadata):
29 """Returns the sqlalchemy Table representing the "revision" table in MediaWiki.
30 :param metadata: metadata = sqlalchemy.MetaData()
32 return Table("revision", metadata,
33 Column("rev_id", types.Integer, nullable=False, primary_key=True),
34 Column("rev_page", types.Integer, nullable=False, primary_key=True),
35 Column("rev_text_id", types.Integer, nullable=False),
36 Column("rev_comment", types.String(convert_unicode='force'), nullable=False), # tinyblob NOT NULL
37 Column("rev_user", types.Integer, nullable=False),
38 Column("rev_user_text", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
39 Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
40 Column("rev_minor_edit", types.Integer, nullable=False),
41 Column("rev_deleted", types.Integer, nullable=False),
42 Column("rev_len", types.Integer, nullable=False),
43 Column("rev_parent_id", types.Integer, nullable=False),
47 def text_table(metadata):
48 """Returns the sqlalchemy Table representing the "text" table in MediaWiki.
49 :param metadata: metadata = sqlalchemy.MetaData()
51 return Table("text", metadata,
52 Column("old_id", types.Integer, primary_key=True),
53 Column("old_text", types.String(convert_unicode='force')), # mediumblob NOT NULL
54 Column("old_flags", types.String(convert_unicode='force')), # tinyblob NOT NULL
58 def user_table(metadata):
59 """Returns the sqlalchemy Table representing the "user" table in MediaWiki.
60 :param metadata: metadata = sqlalchemy.MetaData()
62 return Table('user', metadata,
63 Column("user_id", types.Integer, primary_key=True),
64 Column("user_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
65 Column("user_real_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
66 Column("user_password", types.UnicodeText, nullable=False), # tinyblob
69 Column("user_email", types.Unicode, nullable=False), # tinytext NOT NULL
72 # "user_email_authenticated"
74 # "user_email_token_expires"
80 def categorylinks_table(metadata):
81 """Returns the sqlalchemy Table representing the "categorylinks" table in MediaWiki.
82 :param metadata: metadata = sqlalchemy.MetaData()
84 return Table("categorylinks", metadata,
85 Column("cl_from", types.Integer, nullable=False, primary_key=True),
86 Column("cl_to", types.Unicode(255), nullable=False, primary_key=True), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
87 Column("cl_sortkey", types.String(convert_unicode='force'), nullable=False), # varbinary(230) NOT NULL
88 Column("cl_timestamp", types.DateTime, nullable=False),