1

I am new to the golang-migrate/migrate library and started playing around with it.

I am interested in creating PostgreSql tables with dynamic names in my Golang app by using the migrate library and the .up.sql files with placeholders. Something like this:

CREATE TABLE IF NOT EXISTS ${my-variable-table-name}(

   id serial PRIMARY KEY,
   email VARCHAR (300) UNIQUE NOT NULL
);

I do know that I can create tables with dynamic names by using the database/sql package with the different Exec() methods as explained here and here. However, I was wondering if this can be accomplished with the migrate library functionality only, without explicitly using the database/sql methods.

I searched a lot for any piece of information but could not find anything.

Thanks in advance!

1
  • 1
    Not directly (see this issue). However there is nothing to stop you using templates to build the migration files (either prior to calling ` m.Up()` or via a custom source e.g. a modified version of file). However this may mean that your migrations are not easily reversible. Commented Jul 27, 2022 at 23:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.