Fix typo in column names in mapping as well.
[philipp/winterrodeln/wrpylib.git] / wrpylib / mwdb.py
index 6858c279adb91c7e80c56b7543aded081aa6ffaa..e0682db1d6c01fd547d5aaa275257d35efbdd32c 100644 (file)
@@ -1,8 +1,7 @@
-#!/usr/bin/python2.6
-# -*- coding: iso-8859-15 -*-
+#!/usr/bin/python3.4
 # $Id$
 # $HeadURL$
 # $Id$
 # $HeadURL$
-"""This module contains code to make tha access of MediaWiki tables
+"""This module contains code to make the access of MediaWiki tables
 easy. The module uses sqlalchemy to access the database.
 """
 from sqlalchemy import Table, Column, types
 easy. The module uses sqlalchemy to access the database.
 """
 from sqlalchemy import Table, Column, types
@@ -15,15 +14,17 @@ def page_table(metadata):
     return Table("page", metadata,
     Column("page_id", types.Integer, primary_key=True),
     Column("page_namespace", types.Integer, nullable=False),
     return Table("page", metadata,
     Column("page_id", types.Integer, primary_key=True),
     Column("page_namespace", types.Integer, nullable=False),
-    Column("page_title", types.Unicode(255), nullable=False),
-    Column("page_restrictions", types.Unicode, nullable=False),
-    Column("page_counter", types.Integer, nullable=False),
+    Column("page_title", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+    Column("page_restrictions", types.String, nullable=False), # tinyblob NOT NULL
     Column("page_is_redirect", types.Integer, nullable=False),
     Column("page_is_new", types.Integer, nullable=False),
     Column("page_random", types.Float, nullable=False),
     Column("page_is_redirect", types.Integer, nullable=False),
     Column("page_is_new", types.Integer, nullable=False),
     Column("page_random", types.Float, nullable=False),
-    Column("page_touched", types.Unicode(14), nullable=False),
+    Column("page_touched", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
     Column("page_latest", types.Integer, nullable=False),
     Column("page_len", types.Integer, nullable=False),
     Column("page_latest", types.Integer, nullable=False),
     Column("page_len", types.Integer, nullable=False),
+    Column("page_content_model", types.String(32, convert_unicode='force')),
+    Column("page_links_updated", types.String(14, convert_unicode='force')),
+    Column("page_lang", types.String(35, convert_unicode='force')),
     )
 
 
     )
 
 
@@ -35,10 +36,10 @@ def revision_table(metadata):
     Column("rev_id", types.Integer, nullable=False, primary_key=True),
     Column("rev_page", types.Integer, nullable=False, primary_key=True),
     Column("rev_text_id", types.Integer, nullable=False),
     Column("rev_id", types.Integer, nullable=False, primary_key=True),
     Column("rev_page", types.Integer, nullable=False, primary_key=True),
     Column("rev_text_id", types.Integer, nullable=False),
-    Column("rev_comment", types.Unicode),
+    Column("rev_comment", types.String(convert_unicode='force'), nullable=False), # tinyblob NOT NULL
     Column("rev_user", types.Integer, nullable=False),
     Column("rev_user", types.Integer, nullable=False),
-    Column("rev_user_text", types.Unicode(255), nullable=False),
-    Column("rev_timestamp", types.Unicode(14), nullable=False),
+    Column("rev_user_text", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+    Column("rev_timestamp", types.String(14, convert_unicode='force'), nullable=False), # binary(14) NOT NULL
     Column("rev_minor_edit", types.Integer, nullable=False),
     Column("rev_deleted", types.Integer, nullable=False),
     Column("rev_len", types.Integer, nullable=False),
     Column("rev_minor_edit", types.Integer, nullable=False),
     Column("rev_deleted", types.Integer, nullable=False),
     Column("rev_len", types.Integer, nullable=False),
@@ -52,8 +53,30 @@ def text_table(metadata):
     """
     return Table("text", metadata,
     Column("old_id", types.Integer, primary_key=True),
     """
     return Table("text", metadata,
     Column("old_id", types.Integer, primary_key=True),
-    Column("old_text", types.Unicode),
-    Column("old_flags", types.Unicode),
+    Column("old_text", types.String(convert_unicode='force')), # mediumblob NOT NULL
+    Column("old_flags", types.String(convert_unicode='force')), # tinyblob NOT NULL
+    )
+
+
+def user_table(metadata):
+    """Returns the sqlalchemy Table representing the "user" table in MediaWiki.
+    :param metadata: metadata = sqlalchemy.MetaData()
+    """
+    return Table('user', metadata,
+    Column("user_id", types.Integer, primary_key=True),
+    Column("user_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+    Column("user_real_name", types.Unicode(255), nullable=False), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+    Column("user_password", types.UnicodeText, nullable=False),  # tinyblob
+    # "user_newpassword"
+    # "user_newpass_time"
+    Column("user_email", types.Unicode, nullable=False), # tinytext NOT NULL
+    # "user_touched"
+    # "user_token"
+    # "user_email_authenticated"
+    # "user_email_token"
+    # "user_email_token_expires"
+    # "user_registration"
+    # "user_editcount"
     )
 
 
     )
 
 
@@ -63,8 +86,7 @@ def categorylinks_table(metadata):
     """
     return Table("categorylinks", metadata,
     Column("cl_from", types.Integer, nullable=False, primary_key=True),
     """
     return Table("categorylinks", metadata,
     Column("cl_from", types.Integer, nullable=False, primary_key=True),
-    Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
-    Column("cl_sortkey", types.Unicode, nullable=False),
+    Column("cl_to", types.Unicode(255), nullable=False, primary_key=True), # varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
+    Column("cl_sortkey", types.String(convert_unicode='force'), nullable=False), # varbinary(230) NOT NULL
     Column("cl_timestamp", types.DateTime, nullable=False),
     )
     Column("cl_timestamp", types.DateTime, nullable=False),
     )
-