[Checkins] SVN: relstorage/trunk/relstorage/adapters/ Merged the schemas into one script

Shane Hathaway shane at hathawaymix.org
Wed Sep 23 22:10:00 EDT 2009


Log message for revision 104467:
  Merged the schemas into one script
  

Changed:
  U   relstorage/trunk/relstorage/adapters/oracle.py
  U   relstorage/trunk/relstorage/adapters/schema.py

-=-
Modified: relstorage/trunk/relstorage/adapters/oracle.py
===================================================================
--- relstorage/trunk/relstorage/adapters/oracle.py	2009-09-23 23:14:01 UTC (rev 104466)
+++ relstorage/trunk/relstorage/adapters/oracle.py	2009-09-24 02:09:58 UTC (rev 104467)
@@ -288,8 +288,7 @@
         try:
             if self._twophase:
                 conn, cursor = self.open(transaction_mode=None, twophase=True)
-                try:
-                    self._set_xid(conn, cursor)
+                self._set_xid(conn, cursor)
             else:
                 conn, cursor = self.open()
             if self.on_store_opened is not None:

Modified: relstorage/trunk/relstorage/adapters/schema.py
===================================================================
--- relstorage/trunk/relstorage/adapters/schema.py	2009-09-23 23:14:01 UTC (rev 104466)
+++ relstorage/trunk/relstorage/adapters/schema.py	2009-09-24 02:09:58 UTC (rev 104467)
@@ -17,118 +17,332 @@
 from zope.interface import implements
 import time
 
-class HistoryPreservingPostgreSQLSchema(object):
-    implements(ISchemaInstaller)
 
-    script = """
-    CREATE TABLE commit_lock ();
+history_preserving_schema = """
 
-    -- The list of all transactions in the database
-    CREATE TABLE transaction (
-        tid         BIGINT NOT NULL PRIMARY KEY,
-        packed      BOOLEAN NOT NULL DEFAULT FALSE,
-        empty       BOOLEAN NOT NULL DEFAULT FALSE,
-        username    BYTEA NOT NULL,
-        description BYTEA NOT NULL,
-        extension   BYTEA
-    );
+# commit_lock: Held during commit.  Another kind of lock is used for MySQL.
 
-    -- Create a special transaction to represent object creation.  This
-    -- row is often referenced by object_state.prev_tid, but never by
-    -- object_state.tid.
-    INSERT INTO transaction (tid, username, description)
-        VALUES (0, 'system', 'special transaction for object creation');
+    postgresql:
+        CREATE TABLE commit_lock ();
 
-    CREATE SEQUENCE zoid_seq;
+    oracle:
+        CREATE TABLE commit_lock (dummy CHAR);
 
-    -- All object states in all transactions.  Note that md5 and state
-    -- can be null to represent object uncreation.
-    CREATE TABLE object_state (
-        zoid        BIGINT NOT NULL,
-        tid         BIGINT NOT NULL REFERENCES transaction
-                    CHECK (tid > 0),
-        PRIMARY KEY (zoid, tid),
-        prev_tid    BIGINT NOT NULL REFERENCES transaction,
-        md5         CHAR(32),
-        state       BYTEA
-    );
-    CREATE INDEX object_state_tid ON object_state (tid);
-    CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
+# pack_lock: Held during pack.  Another kind of lock is used for MySQL.
+# Another kind of lock is used for PostgreSQL >= 8.2.
 
-    -- Pointers to the current object state
-    CREATE TABLE current_object (
-        zoid        BIGINT NOT NULL PRIMARY KEY,
-        tid         BIGINT NOT NULL,
-        FOREIGN KEY (zoid, tid) REFERENCES object_state
-    );
-    CREATE INDEX current_object_tid ON current_object (tid);
+    oracle:
+        CREATE TABLE pack_lock (dummy CHAR);
 
-    -- A list of referenced OIDs from each object_state.
-    -- This table is populated as needed during packing.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because rows in object_state
-    -- are never modified once committed, and rows are removed
-    -- from object_state only by packing.
-    CREATE TABLE object_ref (
-        zoid        BIGINT NOT NULL,
-        tid         BIGINT NOT NULL,
-        to_zoid     BIGINT NOT NULL,
-        PRIMARY KEY (tid, zoid, to_zoid)
-    );
+# transaction: The list of all transactions in the database. Create a
+# special '0' transaction to represent object creation. The '0'
+# transaction is often referenced by object_state.prev_tid, but never
+# by object_state.tid.
 
-    -- The object_refs_added table tracks whether object_refs has
-    -- been populated for all states in a given transaction.
-    -- An entry is added only when the work is finished.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because object states
-    -- are never added to a transaction once committed, and
-    -- rows are removed from the transaction table only by
-    -- packing.
-    CREATE TABLE object_refs_added (
-        tid         BIGINT NOT NULL PRIMARY KEY
-    );
+    postgresql:
+        CREATE TABLE transaction (
+            tid         BIGINT NOT NULL PRIMARY KEY,
+            packed      BOOLEAN NOT NULL DEFAULT FALSE,
+            empty       BOOLEAN NOT NULL DEFAULT FALSE,
+            username    BYTEA NOT NULL,
+            description BYTEA NOT NULL,
+            extension   BYTEA
+        );
+        INSERT INTO transaction (tid, username, description)
+            VALUES (0, 'system', 'special transaction for object creation');
 
-    -- Temporary state during packing:
-    -- The list of objects to pack.  If keep is false,
-    -- the object and all its revisions will be removed.
-    -- If keep is true, instead of removing the object,
-    -- the pack operation will cut the object's history.
-    -- The keep_tid field specifies the oldest revision
-    -- of the object to keep.
-    -- The visited flag is set when pre_pack is visiting an object's
-    -- references, and remains set.
-    CREATE TABLE pack_object (
-        zoid        BIGINT NOT NULL PRIMARY KEY,
-        keep        BOOLEAN NOT NULL,
-        keep_tid    BIGINT NOT NULL,
-        visited     BOOLEAN NOT NULL DEFAULT FALSE
-    );
-    CREATE INDEX pack_object_keep_false ON pack_object (zoid)
-        WHERE keep = false;
-    CREATE INDEX pack_object_keep_true ON pack_object (visited)
-        WHERE keep = true;
+    mysql:
+        CREATE TABLE transaction (
+            tid         BIGINT NOT NULL PRIMARY KEY,
+            packed      BOOLEAN NOT NULL DEFAULT FALSE,
+            empty       BOOLEAN NOT NULL DEFAULT FALSE,
+            username    BLOB NOT NULL,
+            description BLOB NOT NULL,
+            extension   BLOB
+        ) ENGINE = InnoDB;
+        INSERT INTO transaction (tid, username, description)
+            VALUES (0, 'system', 'special transaction for object creation');
 
-    -- Temporary state during packing: the list of object states to pack.
-    CREATE TABLE pack_state (
-        tid         BIGINT NOT NULL,
-        zoid        BIGINT NOT NULL,
-        PRIMARY KEY (tid, zoid)
-    );
+    oracle:
+        CREATE TABLE transaction (
+            tid         NUMBER(20) NOT NULL PRIMARY KEY,
+            packed      CHAR DEFAULT 'N' CHECK (packed IN ('N', 'Y')),
+            empty       CHAR DEFAULT 'N' CHECK (empty IN ('N', 'Y')),
+            username    RAW(500),
+            description RAW(2000),
+            extension   RAW(2000)
+        );
+        INSERT INTO transaction (tid, username, description)
+            VALUES (0,
+            UTL_I18N.STRING_TO_RAW('system', 'US7ASCII'),
+            UTL_I18N.STRING_TO_RAW(
+                'special transaction for object creation', 'US7ASCII'));
 
-    -- Temporary state during packing: the list of transactions that
-    -- have at least one object state to pack.
-    CREATE TABLE pack_state_tid (
-        tid         BIGINT NOT NULL PRIMARY KEY
-    );
-    """
+# OID allocation
 
+    postgresql:
+        CREATE SEQUENCE zoid_seq;
+
+    mysql:
+        CREATE TABLE new_oid (
+            zoid        BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT
+        ) ENGINE = InnoDB;
+
+    oracle:
+        CREATE SEQUENCE zoid_seq;
+
+# object_state: All object states in all transactions. Note that md5
+# and state can be null to represent object uncreation.
+
+    postgresql:
+        CREATE TABLE object_state (
+            zoid        BIGINT NOT NULL,
+            tid         BIGINT NOT NULL REFERENCES transaction
+                        CHECK (tid > 0),
+            PRIMARY KEY (zoid, tid),
+            prev_tid    BIGINT NOT NULL REFERENCES transaction,
+            md5         CHAR(32),
+            state       BYTEA
+        );
+        CREATE INDEX object_state_tid ON object_state (tid);
+        CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
+
+    mysql:
+        CREATE TABLE object_state (
+            zoid        BIGINT NOT NULL,
+            tid         BIGINT NOT NULL REFERENCES transaction,
+            PRIMARY KEY (zoid, tid),
+            prev_tid    BIGINT NOT NULL REFERENCES transaction,
+            md5         CHAR(32) CHARACTER SET ascii,
+            state       LONGBLOB,
+            CHECK (tid > 0)
+        ) ENGINE = InnoDB;
+        CREATE INDEX object_state_tid ON object_state (tid);
+        CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
+
+    oracle:
+        CREATE TABLE object_state (
+            zoid        NUMBER(20) NOT NULL,
+            tid         NUMBER(20) NOT NULL REFERENCES transaction
+                        CHECK (tid > 0),
+            PRIMARY KEY (zoid, tid),
+            prev_tid    NUMBER(20) NOT NULL REFERENCES transaction,
+            md5         CHAR(32),
+            state       BLOB
+        );
+        CREATE INDEX object_state_tid ON object_state (tid);
+        CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
+
+# current_object: Pointers to the current object state
+
+    postgresql:
+        CREATE TABLE current_object (
+            zoid        BIGINT NOT NULL PRIMARY KEY,
+            tid         BIGINT NOT NULL,
+            FOREIGN KEY (zoid, tid) REFERENCES object_state
+        );
+        CREATE INDEX current_object_tid ON current_object (tid);
+
+    mysql:
+        CREATE TABLE current_object (
+            zoid        BIGINT NOT NULL PRIMARY KEY,
+            tid         BIGINT NOT NULL,
+            FOREIGN KEY (zoid, tid) REFERENCES object_state (zoid, tid)
+        ) ENGINE = InnoDB;
+        CREATE INDEX current_object_tid ON current_object (tid);
+
+    oracle:
+        CREATE TABLE current_object (
+            zoid        NUMBER(20) NOT NULL PRIMARY KEY,
+            tid         NUMBER(20) NOT NULL,
+            FOREIGN KEY (zoid, tid) REFERENCES object_state
+        );
+        CREATE INDEX current_object_tid ON current_object (tid);
+
+# object_ref: A list of referenced OIDs from each object_state. This
+# table is populated as needed during packing. To prevent unnecessary
+# table locking, it does not use foreign keys, which is safe because
+# rows in object_state are never modified once committed, and rows are
+# removed from object_state only by packing.
+
+    postgresql:
+        CREATE TABLE object_ref (
+            zoid        BIGINT NOT NULL,
+            tid         BIGINT NOT NULL,
+            to_zoid     BIGINT NOT NULL,
+            PRIMARY KEY (tid, zoid, to_zoid)
+        );
+
+    mysql:
+        CREATE TABLE object_ref (
+            zoid        BIGINT NOT NULL,
+            tid         BIGINT NOT NULL,
+            to_zoid     BIGINT NOT NULL,
+            PRIMARY KEY (tid, zoid, to_zoid)
+        ) ENGINE = MyISAM;
+
+    oracle:
+        CREATE TABLE object_ref (
+            zoid        NUMBER(20) NOT NULL,
+            tid         NUMBER(20) NOT NULL,
+            to_zoid     NUMBER(20) NOT NULL,
+            PRIMARY KEY (tid, zoid, to_zoid)
+        );
+
+# The object_refs_added table tracks whether object_refs has been
+# populated for all states in a given transaction. An entry is added
+# only when the work is finished. To prevent unnecessary table locking,
+# it does not use foreign keys, which is safe because object states are
+# never added to a transaction once committed, and rows are removed
+# from the transaction table only by packing.
+
+    postgresql:
+        CREATE TABLE object_refs_added (
+            tid         BIGINT NOT NULL PRIMARY KEY
+        );
+
+    mysql:
+        CREATE TABLE object_refs_added (
+            tid         BIGINT NOT NULL PRIMARY KEY
+        ) ENGINE = MyISAM;
+
+    oracle:
+        CREATE TABLE object_refs_added (
+            tid         NUMBER(20) NOT NULL PRIMARY KEY
+        );
+
+# pack_object: Temporary state during packing: The list of objects to
+# pack. If keep is false, the object and all its revisions will be
+# removed. If keep is true, instead of removing the object, the pack
+# operation will cut the object's history. The keep_tid field specifies
+# the oldest revision of the object to keep. The visited flag is set
+# when pre_pack is visiting an object's references, and remains set.
+
+    postgresql:
+        CREATE TABLE pack_object (
+            zoid        BIGINT NOT NULL PRIMARY KEY,
+            keep        BOOLEAN NOT NULL,
+            keep_tid    BIGINT NOT NULL,
+            visited     BOOLEAN NOT NULL DEFAULT FALSE
+        );
+        CREATE INDEX pack_object_keep_false ON pack_object (zoid)
+            WHERE keep = false;
+        CREATE INDEX pack_object_keep_true ON pack_object (visited)
+            WHERE keep = true;
+
+    mysql:
+        CREATE TABLE pack_object (
+            zoid        BIGINT NOT NULL PRIMARY KEY,
+            keep        BOOLEAN NOT NULL,
+            keep_tid    BIGINT NOT NULL,
+            visited     BOOLEAN NOT NULL DEFAULT FALSE
+        ) ENGINE = MyISAM;
+        CREATE INDEX pack_object_keep_zoid ON pack_object (keep, zoid);
+
+    oracle:
+        CREATE TABLE pack_object (
+            zoid        NUMBER(20) NOT NULL PRIMARY KEY,
+            keep        CHAR NOT NULL CHECK (keep IN ('N', 'Y')),
+            keep_tid    NUMBER(20) NOT NULL,
+            visited     CHAR DEFAULT 'N' NOT NULL CHECK (visited IN ('N', 'Y'))
+        );
+        CREATE INDEX pack_object_keep_zoid ON pack_object (keep, zoid);
+
+# pack_state: Temporary state during packing: the list of object states
+# to pack.
+
+    postgresql:
+        CREATE TABLE pack_state (
+            tid         BIGINT NOT NULL,
+            zoid        BIGINT NOT NULL,
+            PRIMARY KEY (tid, zoid)
+        );
+
+    mysql:
+        CREATE TABLE pack_state (
+            tid         BIGINT NOT NULL,
+            zoid        BIGINT NOT NULL,
+            PRIMARY KEY (tid, zoid)
+        ) ENGINE = MyISAM;
+
+    oracle:
+        CREATE TABLE pack_state (
+            tid         NUMBER(20) NOT NULL,
+            zoid        NUMBER(20) NOT NULL,
+            PRIMARY KEY (tid, zoid)
+        );
+
+# pack_state_tid: Temporary state during packing: the list of
+# transactions that have at least one object state to pack.
+
+    postgresql:
+        CREATE TABLE pack_state_tid (
+            tid         BIGINT NOT NULL PRIMARY KEY
+        );
+
+    mysql:
+        CREATE TABLE pack_state_tid (
+            tid         BIGINT NOT NULL PRIMARY KEY
+        ) ENGINE = MyISAM;
+
+    oracle:
+        CREATE TABLE pack_state_tid (
+            tid         NUMBER(20) NOT NULL PRIMARY KEY
+        );
+
+# Oracle expects temporary tables to be created ahead of time, while
+# MySQL and PostgreSQL expect them to be created in the session.
+
+    oracle:
+        # States that will soon be stored
+        CREATE GLOBAL TEMPORARY TABLE temp_store (
+            zoid        NUMBER(20) NOT NULL PRIMARY KEY,
+            prev_tid    NUMBER(20) NOT NULL,
+            md5         CHAR(32),
+            state       BLOB
+        ) ON COMMIT DELETE ROWS;
+
+        # Temporary state during packing: a list of objects
+        # whose references need to be examined.
+        CREATE GLOBAL TEMPORARY TABLE temp_pack_visit (
+            zoid        NUMBER(20) NOT NULL PRIMARY KEY,
+            keep_tid    NUMBER(20)
+        );
+
+        # Temporary state during undo: a list of objects
+        # to be undone and the tid of the undone state.
+        CREATE GLOBAL TEMPORARY TABLE temp_undo (
+            zoid        NUMBER(20) NOT NULL PRIMARY KEY,
+            prev_tid    NUMBER(20) NOT NULL
+        );
+"""
+
+def filter_schema(schema, database):
+    res = []
+    match = False
+    for line in schema.splitlines():
+        line = line.strip()
+        if not line or line.startswith('#'):
+            continue
+        if line.endswith(':'):
+            match = (database in line[:-1].split())
+            continue
+        if match:
+            res.append(line)
+    return '\n'.join(res)
+
+
+class HistoryPreservingPostgreSQLSchema(object):
+    implements(ISchemaInstaller)
+
     def __init__(self, locker, connmanager):
         self.locker = locker
         self.connmanager = connmanager
 
     def create(self, cursor):
         """Create the database tables."""
-        cursor.execute(self.script)
+        script = filter_schema(history_preserving_schema, 'postgresql')
+        cursor.execute(script)
         self.locker.create_pack_lock(cursor)
 
     def prepare(self):
@@ -177,114 +391,14 @@
 class HistoryPreservingMySQLSchema(object):
     implements(ISchemaInstaller)
 
-    script = """
-    -- The list of all transactions in the database
-    CREATE TABLE transaction (
-        tid         BIGINT NOT NULL PRIMARY KEY,
-        packed      BOOLEAN NOT NULL DEFAULT FALSE,
-        empty       BOOLEAN NOT NULL DEFAULT FALSE,
-        username    BLOB NOT NULL,
-        description BLOB NOT NULL,
-        extension   BLOB
-    ) ENGINE = InnoDB;
-
-    -- Create a special transaction to represent object creation.  This
-    -- row is often referenced by object_state.prev_tid, but never by
-    -- object_state.tid.
-    INSERT INTO transaction (tid, username, description)
-        VALUES (0, 'system', 'special transaction for object creation');
-
-    -- All OIDs allocated in the database.  Note that this table
-    -- is purposely non-transactional.
-    CREATE TABLE new_oid (
-        zoid        BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT
-    ) ENGINE = MyISAM;
-
-    -- All object states in all transactions.  Note that md5 and state
-    -- can be null to represent object uncreation.
-    CREATE TABLE object_state (
-        zoid        BIGINT NOT NULL,
-        tid         BIGINT NOT NULL REFERENCES transaction,
-        PRIMARY KEY (zoid, tid),
-        prev_tid    BIGINT NOT NULL REFERENCES transaction,
-        md5         CHAR(32) CHARACTER SET ascii,
-        state       LONGBLOB,
-        CHECK (tid > 0)
-    ) ENGINE = InnoDB;
-    CREATE INDEX object_state_tid ON object_state (tid);
-    CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
-
-    -- Pointers to the current object state
-    CREATE TABLE current_object (
-        zoid        BIGINT NOT NULL PRIMARY KEY,
-        tid         BIGINT NOT NULL,
-        FOREIGN KEY (zoid, tid) REFERENCES object_state (zoid, tid)
-    ) ENGINE = InnoDB;
-    CREATE INDEX current_object_tid ON current_object (tid);
-
-    -- A list of referenced OIDs from each object_state.
-    -- This table is populated as needed during packing.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because rows in object_state
-    -- are never modified once committed, and rows are removed
-    -- from object_state only by packing.
-    CREATE TABLE object_ref (
-        zoid        BIGINT NOT NULL,
-        tid         BIGINT NOT NULL,
-        to_zoid     BIGINT NOT NULL,
-        PRIMARY KEY (tid, zoid, to_zoid)
-    ) ENGINE = MyISAM;
-
-    -- The object_refs_added table tracks whether object_refs has
-    -- been populated for all states in a given transaction.
-    -- An entry is added only when the work is finished.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because object states
-    -- are never added to a transaction once committed, and
-    -- rows are removed from the transaction table only by
-    -- packing.
-    CREATE TABLE object_refs_added (
-        tid         BIGINT NOT NULL PRIMARY KEY
-    ) ENGINE = MyISAM;
-
-    -- Temporary state during packing:
-    -- The list of objects to pack.  If keep is false,
-    -- the object and all its revisions will be removed.
-    -- If keep is true, instead of removing the object,
-    -- the pack operation will cut the object's history.
-    -- The keep_tid field specifies the oldest revision
-    -- of the object to keep.
-    -- The visited flag is set when pre_pack is visiting an object's
-    -- references, and remains set.
-    CREATE TABLE pack_object (
-        zoid        BIGINT NOT NULL PRIMARY KEY,
-        keep        BOOLEAN NOT NULL,
-        keep_tid    BIGINT NOT NULL,
-        visited     BOOLEAN NOT NULL DEFAULT FALSE
-    ) ENGINE = MyISAM;
-    CREATE INDEX pack_object_keep_zoid ON pack_object (keep, zoid);
-
-    -- Temporary state during packing: the list of object states to pack.
-    CREATE TABLE pack_state (
-        tid         BIGINT NOT NULL,
-        zoid        BIGINT NOT NULL,
-        PRIMARY KEY (tid, zoid)
-    ) ENGINE = MyISAM;
-
-    -- Temporary state during packing: the list of transactions that
-    -- have at least one object state to pack.
-    CREATE TABLE pack_state_tid (
-        tid         BIGINT NOT NULL PRIMARY KEY
-    ) ENGINE = MyISAM;
-    """
-
     def __init__(self, connmanager, runner):
         self.connmanager = connmanager
         self.runner = runner
 
     def create(self, cursor):
         """Create the database tables."""
-        self.runner.run_script(cursor, self.script)
+        script = filter_schema(history_preserving_schema, 'mysql')
+        self.runner.run_script(cursor, script)
 
     def prepare(self):
         """Create the database schema if it does not already exist."""
@@ -325,140 +439,14 @@
 class HistoryPreservingOracleSchema(object):
     implements(ISchemaInstaller)
 
-    script = """
-    CREATE TABLE commit_lock (dummy CHAR);
-
-    -- The list of all transactions in the database
-    CREATE TABLE transaction (
-        tid         NUMBER(20) NOT NULL PRIMARY KEY,
-        packed      CHAR DEFAULT 'N' CHECK (packed IN ('N', 'Y')),
-        empty       CHAR DEFAULT 'N' CHECK (empty IN ('N', 'Y')),
-        username    RAW(500),
-        description RAW(2000),
-        extension   RAW(2000)
-    );
-
-    -- Create a special transaction to represent object creation.  This
-    -- row is often referenced by object_state.prev_tid, but never by
-    -- object_state.tid.
-    INSERT INTO transaction (tid, username, description)
-        VALUES (0,
-        UTL_I18N.STRING_TO_RAW('system', 'US7ASCII'),
-        UTL_I18N.STRING_TO_RAW(
-            'special transaction for object creation', 'US7ASCII'));
-
-    CREATE SEQUENCE zoid_seq;
-
-    -- All object states in all transactions.
-    -- md5 and state can be null to represent object uncreation.
-    CREATE TABLE object_state (
-        zoid        NUMBER(20) NOT NULL,
-        tid         NUMBER(20) NOT NULL REFERENCES transaction
-                    CHECK (tid > 0),
-        PRIMARY KEY (zoid, tid),
-        prev_tid    NUMBER(20) NOT NULL REFERENCES transaction,
-        md5         CHAR(32),
-        state       BLOB
-    );
-    CREATE INDEX object_state_tid ON object_state (tid);
-    CREATE INDEX object_state_prev_tid ON object_state (prev_tid);
-
-    -- Pointers to the current object state
-    CREATE TABLE current_object (
-        zoid        NUMBER(20) NOT NULL PRIMARY KEY,
-        tid         NUMBER(20) NOT NULL,
-        FOREIGN KEY (zoid, tid) REFERENCES object_state
-    );
-    CREATE INDEX current_object_tid ON current_object (tid);
-
-    -- States that will soon be stored
-    CREATE GLOBAL TEMPORARY TABLE temp_store (
-        zoid        NUMBER(20) NOT NULL PRIMARY KEY,
-        prev_tid    NUMBER(20) NOT NULL,
-        md5         CHAR(32),
-        state       BLOB
-    ) ON COMMIT DELETE ROWS;
-
-    -- During packing, an exclusive lock is held on pack_lock.
-    CREATE TABLE pack_lock (dummy CHAR);
-
-    -- A list of referenced OIDs from each object_state.
-    -- This table is populated as needed during packing.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because rows in object_state
-    -- are never modified once committed, and rows are removed
-    -- from object_state only by packing.
-    CREATE TABLE object_ref (
-        zoid        NUMBER(20) NOT NULL,
-        tid         NUMBER(20) NOT NULL,
-        to_zoid     NUMBER(20) NOT NULL,
-        PRIMARY KEY (tid, zoid, to_zoid)
-    );
-
-    -- The object_refs_added table tracks whether object_refs has
-    -- been populated for all states in a given transaction.
-    -- An entry is added only when the work is finished.
-    -- To prevent unnecessary table locking, it does not use
-    -- foreign keys, which is safe because object states
-    -- are never added to a transaction once committed, and
-    -- rows are removed from the transaction table only by
-    -- packing.
-    CREATE TABLE object_refs_added (
-        tid         NUMBER(20) NOT NULL PRIMARY KEY
-    );
-
-    -- Temporary state during packing:
-    -- The list of objects to pack.  If keep is 'N',
-    -- the object and all its revisions will be removed.
-    -- If keep is 'Y', instead of removing the object,
-    -- the pack operation will cut the object's history.
-    -- The keep_tid field specifies the oldest revision
-    -- of the object to keep.
-    -- The visited flag is set when pre_pack is visiting an object's
-    -- references, and remains set.
-    CREATE TABLE pack_object (
-        zoid        NUMBER(20) NOT NULL PRIMARY KEY,
-        keep        CHAR NOT NULL CHECK (keep IN ('N', 'Y')),
-        keep_tid    NUMBER(20) NOT NULL,
-        visited     CHAR DEFAULT 'N' NOT NULL CHECK (visited IN ('N', 'Y'))
-    );
-    CREATE INDEX pack_object_keep_zoid ON pack_object (keep, zoid);
-
-    -- Temporary state during packing: the list of object states to pack.
-    CREATE TABLE pack_state (
-        tid         NUMBER(20) NOT NULL,
-        zoid        NUMBER(20) NOT NULL,
-        PRIMARY KEY (tid, zoid)
-    );
-
-    -- Temporary state during packing: the list of transactions that
-    -- have at least one object state to pack.
-    CREATE TABLE pack_state_tid (
-        tid         NUMBER(20) NOT NULL PRIMARY KEY
-    );
-
-    -- Temporary state during packing: a list of objects
-    -- whose references need to be examined.
-    CREATE GLOBAL TEMPORARY TABLE temp_pack_visit (
-        zoid        NUMBER(20) NOT NULL PRIMARY KEY,
-        keep_tid    NUMBER(20)
-    );
-
-    -- Temporary state during undo: a list of objects
-    -- to be undone and the tid of the undone state.
-    CREATE GLOBAL TEMPORARY TABLE temp_undo (
-        zoid        NUMBER(20) NOT NULL PRIMARY KEY,
-        prev_tid    NUMBER(20) NOT NULL
-    );
-    """
-
     def __init__(self, connmanager, runner):
         self.connmanager = connmanager
         self.runner = runner
 
     def create(self, cursor):
         """Create the database tables."""
-        self.runner.run_script(cursor, self.script)
+        script = filter_schema(history_preserving_schema, 'oracle')
+        self.runner.run_script(cursor, script)
         # Let Oracle catch up with the new data definitions by sleeping.
         # This reduces the likelihood of spurious ORA-01466 errors.
         time.sleep(5)



More information about the checkins mailing list