Closed olivermt closed 10 years ago
The dialect doesn't check the max value of each table because it hasn't designed for that case. I mean, the dialect is intended to be used in a fresh start application when all the sequences are created with initial value equals 1.
I think you may have installed the plugin in an existing application and you get duplicates. You can create a programmatically db migration that gets the max value of every table and set the related sequence to that value.
However I'm going to think a way to provide a new dialect or configuration option to disable the sequence-per-table setting.
@alotor, what do you think?
Thanks for your report.
Regards, Iván. El 07/08/2014 18:56, "Oliver Severin Tynes" notifications@github.com escribió:
I would like a setting that allows me to keep the original PGSQL dialect that had a global sequence.
I do not know enough about sequences, but it seems to me that unless your dialect makes sure these sequences start at max(id) of the existing table, a collision might occur.
As I can see it from liquibase generation, the sequences do not take this into account.
— Reply to this email directly or view it on GitHub https://github.com/kaleidos/grails-postgresql-extensions/issues/49.
I use db-migration.
Are the per-table sequences a requirement for using these extensions?
If not, a nice workaround for now is to simply not run those migrations.
You mean if using the sequence-per-table are a requirement for using this plugin? In that case no, it's not mandatory.
We configured the sequence this way because we think it's better use one sequence per table instead of a global one.
I'm looking into this and it seems that it's not possible to pass a parameter and get it during dialect instantiation. I think I'm going to create a different dialect.
If you are using the grails-db-migration plugin you can create a groovy custom migration and set the value of the sequences with the max(id) of every table.
I give up. Using the debugger I have access to grailsApplication and from it I can get a property to check if I've to create the sequences or not.
But in runtime I get a ClassCastException.
I think I'm going with two dialects :-(
@oteren do you need this new dialect asap or you can wait 2 weeks. I would like to talk with @Alotor but now he is out on holidays.
Sooner is always better than later, but this is actually a part of a large application rewrite, so I can just work on other parts while I wait.
I wouldn't mind dedicating a day or two to dig into this.
If you can handle the if(someSetting) { //do new sequences} else { //do nothing? }
I can hook in the settings. I have done quite a bit of plugin development and it seems like this code runs at a level where it should be possible to get ahold of the settings.
Just point me to which file / line number you want to be able to read a boolean and I will spend the weekend looking around.
Thank you for your offer!
The sequence per table is generated here: https://github.com/kaleidos/grails-postgresql-extensions/blob/master/src/java/net/kaleidos/hibernate/PostgresqlExtensionsDialect.java#L55
I've digging around and in the superclass I've found this code:
ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER );
I can execute it in my configure
method and in the debugger the inner type is GrailsAnnotationConfiguration
but I cann't cast it:
// This doesn't work
GrailsAnnotationConfiguration normalizer2 = (GrailsAnnotationConfiguration) params.get( IDENTIFIER_NORMALIZER );
With the debugger I also see that in this object the grailsApplication
exists and from there I could access to the configuration.
I've also being trying to create a custom config class:
// This file goes in src/groovy/.....
public class MyConfig extends GrailsAnnotationConfiguration {
private GrailsApplication grailsApplication;
@Override
public void setSessionFactoryBeanName(String name) {
super.setSessionFactoryBeanName(name);
Properties p = new Properties();
p.put("myProp", "myValue");
addProperties(p);
System.out.println("Executed!");
}
public void setGrailsApplication(GrailsApplication grailsApplication) {
this.grailsApplication = grailsApplication;
}
}
And use it in DataSource.groovy
dataSource {
configClass = net.kaleidos.hibernate.MyConfig
dbCreate = "" // one of '', 'create', 'create-drop','update'
driverClassName = "org.postgresql.Driver"
...
}
I can override a lot of methods and I have access to grailsApplication
but I cann't figure out how to add some property that I can access during the sequences creation.
I hope you have more luck.
Regards, Iván.
I agree on a separate dialect, after digging around a lot and trying to read config in a sane way.
I've found the way to read a property in the dialect. I hope to be able to create the pull request and the update in the documentation this afternoon or this night.
Published versions 4.3.0 and 3.3.0 with a new flag for configure the sequence-per-table.
Please check the documentation: https://github.com/kaleidos/grails-postgresql-extensions#configuration
I would like a setting that allows me to keep the original PGSQL dialect that had a global sequence.
I do not know enough about sequences, but it seems to me that unless your dialect makes sure these sequences start at max(id) of the existing table, a collision might occur.
As I can see it from liquibase generation, the sequences do not take this into account.