Running the migrondi up command second time output error message and nothing else happens
Closed this issue · 2 comments
Describe the bug
Trying to run migrondi up
or migrondi down
after the first migrondi up
gives always an error message "42P07: relation "migration" already exists" as an output and nothing else happens.
To Reproduce
Steps to reproduce the behavior:
- Run command
migrondi up
- Run command
migrondi up
ormigrondi down
Expected behavior
Both commands (migrondi up
and migrondi down
) should work without any errors related to 'migrations' table existence still after the first run.
Screenshots
Desktop (please complete the following information):
- OS: Windows, Linux (Manjaro)
- Database: PostgreSQL
- Version: 0.7.0
Additional context
I assume that problem exists inside of the Queries.createMigrationsTable function which is used as a implementation for Queries.ensureMigrationsTable functionality. There seems to be handling for situations when table already exists for SQLite databases, but how about other database types?
This is an interesting situation, I'll try to reproduce later on I did test often in postgresql so it hits me in a weird way.
I'd have a few more questions in regards to this
- does this happen with any particular schema
- did it happen with an schema that contains "migration" as a table as well?
I ask this because the error looks as if there's something trying to add to the migration table
relation "migration" already exists
the key word here being relation I haven't seen that kind of error message before
There seems to be handling for situations when table already exists for SQLite databases, but how about other database types?
We cover each database individually
in Queries.fs:145
we have the createMigrationsTable
function that calls createTableQuery
let private createTableQuery driver =
match driver with
| Driver.Sqlite ->
"""
CREATE TABLE migration(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255) NOT NULL,
timestamp BIGINT NOT NULL
);
"""
| Driver.Postgresql ->
"""
CREATE TABLE migration(
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
timestamp BIGINT NOT NULL
);
"""
| Driver.Mysql ->
"""
CREATE TABLE migration(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
timestamp BIGINT NOT NULL
);
"""
| Driver.Mssql ->
"""
CREATE TABLE dbo.migration(
id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
timestamp BIGINT NOT NULL
);
"""
I guess I could modify those to include a if not exists
clause and even maybe use a not so common name __migondi__migrations
or something like that
In any case I'll report back thanks for raising the issue
This has been fixed in v0.7.1 and is being indexed by nuget, I'll publish a GH release soon as well, feel free to re-open if for some reason it doesn't work