Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Be able to disable sequence-per-table #49

Closed
olivermt opened this issue Aug 7, 2014 · 9 comments
Closed

Request: Be able to disable sequence-per-table #49

olivermt opened this issue Aug 7, 2014 · 9 comments

Comments

@olivermt
Copy link

olivermt commented Aug 7, 2014

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.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 7, 2014

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" [email protected]
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
#49.

@olivermt
Copy link
Author

olivermt commented Aug 8, 2014

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.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 8, 2014

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.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 8, 2014

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.

@olivermt
Copy link
Author

olivermt commented Aug 8, 2014

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.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 8, 2014

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.

@olivermt
Copy link
Author

I agree on a separate dialect, after digging around a lot and trying to read config in a sane way.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 17, 2014

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.

@ilopmar
Copy link
Collaborator

ilopmar commented Aug 18, 2014

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

@ilopmar ilopmar closed this as completed Aug 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants