4 """This module contains code to make the access of MediaWiki tables
5 easy. The module uses sqlalchemy to access the database.
7 from sqlalchemy import Table, Column, types
10 def page_table(metadata):
11 """Returns the sqlalchemy Table representing the "page" table in MediaWiki.
12 :param metadata: metadata = sqlalchemy.MetaData()
14 return Table("page", metadata,
15 Column("page_id", types.Integer, primary_key=True),
16 Column("page_namespace", types.Integer, nullable=False),
17 Column("page_title", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
18 Column("page_restrictions", types.String, nullable=False), # tinyblob NOT NULL
19 Column("page_is_redirect", types.Integer, nullable=False),
20 Column("page_is_new", types.Integer, nullable=False),
21 Column("page_random", types.Float, nullable=False),
22 Column("page_touched", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
23 Column("page_latest", types.Integer, nullable=False),
24 Column("page_len", types.Integer, nullable=False),
25 Column("page_content_model", types.String(32, convert_unicode='force')),
26 Column("page_links_updated", types.String(14, convert_unicode='force')),
27 Column("page_lang", types.String(35, convert_unicode='force')),
31 def revision_table(metadata):
32 """Returns the sqlalchemy Table representing the "revision" table in MediaWiki.
33 :param metadata: metadata = sqlalchemy.MetaData()
35 return Table("revision", metadata,
36 Column("rev_id", types.Integer, nullable=False, primary_key=True),
37 Column("rev_page", types.Integer, nullable=False, primary_key=True),
38 Column("rev_text_id", types.Integer, nullable=False),
39 Column("rev_comment", types.String(convert_unicode='force'), nullable=False), # tinyblob NOT NULL
40 Column("rev_user", types.Integer, nullable=False),
41 Column("rev_user_text", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
42 Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
43 Column("rev_minor_edit", types.Integer, nullable=False),
44 Column("rev_deleted", types.Integer, nullable=False),
45 Column("rev_len", types.Integer, nullable=False),
46 Column("rev_parent_id", types.Integer, nullable=False),
50 def text_table(metadata):
51 """Returns the sqlalchemy Table representing the "text" table in MediaWiki.
52 :param metadata: metadata = sqlalchemy.MetaData()
54 return Table("text", metadata,
55 Column("old_id", types.Integer, primary_key=True),
56 Column("old_text", types.String(convert_unicode='force')), # mediumblob NOT NULL
57 Column("old_flags", types.String(convert_unicode='force')), # tinyblob NOT NULL
61 def user_table(metadata):
62 """Returns the sqlalchemy Table representing the "user" table in MediaWiki.
63 :param metadata: metadata = sqlalchemy.MetaData()
65 return Table('user', metadata,
66 Column("user_id", types.Integer, primary_key=True),
67 Column("user_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
68 Column("user_real_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
69 Column("user_password", types.UnicodeText, nullable=False), # tinyblob
72 Column("user_email", types.Unicode, nullable=False), # tinytext NOT NULL
75 # "user_email_authenticated"
77 # "user_email_token_expires"
83 def categorylinks_table(metadata):
84 """Returns the sqlalchemy Table representing the "categorylinks" table in MediaWiki.
85 :param metadata: metadata = sqlalchemy.MetaData()
87 return Table("categorylinks", metadata,
88 Column("cl_from", types.Integer, nullable=False, primary_key=True),
89 Column("cl_to", types.Unicode(255), nullable=False, primary_key=True), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
90 Column("cl_sortkey", types.String(convert_unicode='force'), nullable=False), # varbinary(230) NOT NULL
91 Column("cl_timestamp", types.DateTime, nullable=False),