Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Migrate.Up() errors out if the latest schema is in use #100

@jon-whit

Description

@jon-whit

Migrate.Up() errors out if the currently active schema matches the latest schema version.

Steps to Reproduce
My migrations look like this:

1_initialize_tables.down.sql

DROP roles_test;
DROP permissions_test;

1_initialize_tables.up.sql

CREATE TABLE permissions_test (
    definition STRING(MAX) NOT NULL,
) PRIMARY KEY (definition);
CREATE TABLE roles_test (
    `parent` STRING(MAX) NOT NULL,
    role_id STRING(MAX) NOT NULL,
) PRIMARY KEY (`parent`, role_id);

I have code that looks like this:

migrator, err := migrate.New(
 "file://migrations",
  "spanner://projects/my-project/instances/main-instance/databases/my-database")
if err != nil {
  log.Fatalf("Unable to instantiate the database schema migrator - %v", err)
}   

// Migrate up to the latest active version
if err := migrator.Up(); err != nil {
  log.Fatalf("Unable to migrate up to the latest database schema - %v", err)
}

And I get the error:

Unable to migrate up to the latest database schema - no change

Expected Behavior
I would expect Migrate.Up() to not return an error if the latest schema is in use. At minimum it should return an ErrAlreadyUpToDate or something similar. If this is not the intended use of this method, better documentation should be made to demonstrate how this functionality is best achieved with the current migrate API.

Migrate Version
v3.5.1 - Go Client

Loaded Source Drivers
file

Loaded Database Drivers
spanner

Additional context
I've ran Migrate.Up() once which created an entry in the SchemaMigrations table and a row now exists that looks like this:

| Version | Dirty |
|---------|-------|
| 1       | False |

The second time I start my service up Migrate.Up() fails because the currently active version is the latest one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions