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

Postgres / SQL multistatement support #1078

Open
bnkamalesh opened this issue Apr 25, 2024 · 0 comments
Open

Postgres / SQL multistatement support #1078

bnkamalesh opened this issue Apr 25, 2024 · 0 comments

Comments

@bnkamalesh
Copy link

Is your feature request related to a problem? Please describe.
In case of Postgres migrations, for initial migrations where we setup schemas, it's common to use CREATE <table> IF NOT EXISTS. Though when creating user defined types, Postgres does not support this. The solution is to wrap type creations in try/catch and ignore duplicate exceptions, as shown below

DO $$ BEGIN
    CREATE TYPE my_custom_type AS ENUM(
        'Hello',
        'world'
    );
EXCEPTION
    WHEN duplicate_object THEN null;
END $$;

I saw there were issues filed for similar cases earlier as well.
ref:
#495 (review)
#1018

I understand the database specific implementations for parsing SQL and why golang-migrate resorted to a simple one based on ;

Describe the solution you'd like
Ability to specify a custom parser via config. e.g. the multistmt package can define an interface like, and accept any implementation.

type Parser interface {
 Parse(reader io.Reader, delimiter []byte, maxMigrationSize int, h Handler) error
}

Describe alternatives you've considered
If the migration returns an error with the specific error (by searching the error text), handle the migration explicitly from within the app, and then force a version upgrade. This seems cumbersome and prone to errors over time.

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

1 participant