Changeset 4418

Show
Ignore:
Timestamp:
04/03/09 21:27:01 (4 years ago)
Author:
gpolo
Message:

Initial support for fk merging.

Location:
branch/merger
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branch/merger/sqlitedb.py

    r4409 r4418  
    1919        self.row_factory = _dict_factory 
    2020 
     21# XXX Missing: 
     22#   Index and trigger merging (read copying) 
     23#   Proper foreign key merging 
    2124 
    2225def merge(new_dbpath, old_dbpath, dry_run=False): 
     
    7780                return 
    7881 
     82            res = new_cursor.execute("pragma foreign_key_list(%s)" % name) 
     83            reference = {} 
     84            for ref in res.fetchall(): 
     85                reference[ref['from']] = (ref['table'], ref['to']) 
     86 
    7987            res = old_cursor.execute("pragma table_info(%s)" % name) 
    8088            old_table_info = res.fetchall() 
     
    102110 
    103111            # Attempt to create new columns 
    104             # XXX not checking if they reference other columns yet. 
    105112            for cname, cinfo in new_by_col.iteritems(): 
    106113                if cinfo['pk']: 
     
    117124                if cinfo['dflt_value']: 
    118125                    query += " DEFAULT %s" % cinfo['dflt_value'] 
     126                if cname in reference: 
     127                    query += " REFERENCES %s(%s)" % reference[cname] 
    119128                old_cursor.execute(query) 
    120129 
  • branch/merger/tests/test_sqlite_column_merge.py

    r4411 r4418  
    5656        conn, cursor = conn_cursor(self.old_db_file.name) 
    5757        # I don't care if the pragma table_info still exists or not, if it 
    58         # doesn't then let the test fail. 
     58        # doesn't then the two next tests will be comparing empty lists. 
    5959        old_table_info = cursor.execute( 
    6060                "pragma table_info(%s)" % table).fetchall() 
     
    8686                "b INTEGER") 
    8787 
    88         # XXX not supported yet 
     88        # XXX not fully supported yet 
    8989        self._verify_merge( 
    90                 "b INTEGER, c INTEGER CONSTRAINT fk REFERENCES d(id)", 
    91                 "b INTEGER") 
     90                "a INTEGER, b INTEGER CONSTRAINT fk REFERENCES d(id)", 
     91                "a INTEGER") 
     92        self._verify_merge( 
     93                "a INTEGER, b INTEGER REFERENCES d(id) ON DELETE CASCADE", 
     94                "a INTEGER") 
    9295 
    9396        self._verify_merge_fails(sqlite.OperationalError,