[DBIx-Class-Devel] [sql-translator] ::Diff tries to modify old table after table rename for PK col name change (#40)

Peter Mottram notifications at github.com
Mon Aug 4 16:56:59 GMT 2014


Time to describe the situation in full...
Assume we have an initial table:
```
CREATE TABLE "foos" (
  "foos_id" serial NOT NULL,
  "wibble" integer,
  PRIMARY KEY ("foos_id")
);
```
Which looks like:
```
                             Table "public.foos"
 Column  |  Type   |                        Modifiers                        
---------+---------+---------------------------------------------------------
 foos_id | integer | not null default nextval('foos_foos_id_seq'::regclass)
 wibble  | integer | 
Indexes:
    "foos_pkey" PRIMARY KEY, btree (foos_id)
```
If we want to rename everything then we need to perform the following:
```
ALTER TABLE foos RENAME foos_id TO bars_id;
ALTER SEQUENCE foos_foos_id_seq RENAME TO bars_bars_id_seq;
ALTER INDEX foos_pkey RENAME TO bars_pkey;
ALTER TABLE foos RENAME TO bars;
```
So we end up with this:
```
                            Table "public.bars"
 Column  |  Type   |                       Modifiers                        
---------+---------+--------------------------------------------------------
 bars_id | integer | not null default nextval('bars_bars_id_seq'::regclass)
 wibble  | integer | 
Indexes:
    "bars_pkey" PRIMARY KEY, btree (bars_id)
```
Handling renamed_from for table and field is not so hard but realising that the sequence and index also need renaming to keep things pretty is not so simple. Maybe the best solution would be to implement a batch_table_alter method in ::Producer::PostgreSQL ? 
I'd appreciate comments here before I head too far down the wrong road.

---
Reply to this email directly or view it on GitHub:
https://github.com/dbsrgits/sql-translator/issues/40#issuecomment-51086609
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class-devel/attachments/20140804/76d7d949/attachment.htm>


More information about the DBIx-Class-Devel mailing list