[DBIx-Class-Devel] [dbsrgits/sql-translator] apply `is_auto_increment` for already existing field (#107)

Eugen Konkov notifications at github.com
Sat Jul 14 13:29:18 GMT 2018


When applying `is_auto_increment` for already existing field

```diff
--- a/lib/HyperMouse/Schema/Result/Language.pm
+++ b/lib/HyperMouse/Schema/Result/Language.pm
@@ -33,6 +33,7 @@ $Z->add_columns(
   },
   language_id => {
     data_type => "integer",
+    is_auto_increment => 1,
     extra => { unsigned => 1 },
   },
     known_from => {
```

the generated upgrade script is:

```
ALTER TABLE language ALTER COLUMN language_id TYPE serial;
```
which fails with error `ERROR:  type "serial" does not exist at`:
```
$(which dbic-migration) --schema_class HyperMouse::Schema --database PostgreSQL -Ilib upgrade
Reading configurations from /home/kes/work/projects/tucha/monkeyman/share/fixtures/13/conf
failed to run SQL in /home/kes/work/projects/tucha/monkeyman/share/migrations/PostgreSQL/upgrade/13-14/001-auto.sql: DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::try {...} (): DBI Exception: DBD::Pg::db do failed: ERROR:  type "serial" does not exist at inline delegation in DBIx::Class::DeploymentHandler for deploy_method->upgrade_single_step (attribute declared in /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm at line 51) line 18
 (running line 'ALTER TABLE language ALTER COLUMN language_id TYPE serial') at /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm line 248.
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /home/kes/work/projects/tucha/monkeyman/local/bin/dbic-migration line 0
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /home/kes/work/projects/tucha/monkeyman/local/bin/dbic-migration line 0
Makefile:132: recipe for target 'dbup' failed
make: *** [dbup] Error 255
```

For already existing field there should be few commands:
```
CREATE SEQUENCE foo_a_seq OWNED BY foo.a;
SELECT setval('foo_a_seq', coalesce(max(a), 0)) FROM foo;
ALTER TABLE foo ALTER COLUMN a SET DEFAULT nextval('foo_a_seq'); 
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/dbsrgits/sql-translator/issues/107
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class-devel/attachments/20180714/27f67a65/attachment.html>


More information about the DBIx-Class-Devel mailing list