commandbox-modules / commandbox-migrations

MIT License
7 stars 9 forks source link

.cfmigrations bad JSON borks migrate tool #35

Closed ghost closed 1 year ago

ghost commented 1 year ago

I just started coding again after a bit of a rest and when I try to uninstall and reinstall my database I get the error:

CommandBox> migrate install

ERROR (5.5.2+00578)

Invalid Syntax Closing [}] not found

\modules\commandbox-migrations\models\BaseMigrationCommand.cfc: line 88
86:         // Check and see if a .cfmigrations.json file exists
87:         if ( fileExists( "#directory#/.cfmigrations.json" ) ) {
88:             variables.cfmigrationsInfo = deserializeJSON( fileRead( "#directory#/.cfmigrations.json" ) );
89:             variables.systemSettings.expandDeepSystemSettings( variables.cfmigrationsInfo );
90:             variables.cfmigrationsInfoType = "cfmigrations";
called from \modules\commandbox-migrations\models\BaseMigrationCommand.cfc: line 11
called from \modules\commandbox-migrations\commands\migrate\install.cfc: line 15
called from \system\services\CommandService.cfc: line 443
called from \system\services\CommandService.cfc: line 225
called from \system\Shell.cfc: line 819
called from \system\Shell.cfc: line 634
called from \system\Bootstrap.cfm: line 160

To enable full stack trace, run config set verboseErrors=true

I tried the following commands and neither fixed the issue:

install migrate init migrate install migrate down migrate up

I managed to track the error to the .cfmigration file generation tool producing bad code in the .cfmigrations.json file. Here is what the bad code looks like:

{
    "default": {
        "manager": "cfmigrations.models.QBMigrationManager",
        "migrationsDirectory": "resources/database/migrations",
        "seedsDirectory": "resources/database/seeds",
        "seedEnvironments" : "development"
        "properties": {
            "defaultGrammar": "AutoDiscover@qb",
            "schema": "${DB_SCHEMA}",
            "migrationsTable": "cfmigrations",
            "connectionInfo": {
                "password": "${DB_PASSWORD}",
                "connectionString": "${DB_CONNECTIONSTRING}",
                "class": "${DB_CLASS}",
                "username": "${DB_USER}",
                "bundleName": "${DB_BUNDLENAME}",
                "bundleVersion": "${DB_BUNDLEVERSION}"
            }
        }
    }
}

Here is what it should look like:

{
    "default": {
        "manager": "cfmigrations.models.QBMigrationManager",
        "migrationsDirectory": "resources/database/migrations",
        "seedsDirectory": "resources/database/seeds",
        "seedEnvironments" : "development",
        "properties": {
            "defaultGrammar": "AutoDiscover@qb",
            "schema": "${DB_SCHEMA}",
            "migrationsTable": "cfmigrations",
            "connectionInfo": {
                "password": "${DB_PASSWORD}",
                "connectionString": "${DB_CONNECTIONSTRING}",
                "class": "${DB_CLASS}",
                "username": "${DB_USER}",
                "bundleName": "${DB_BUNDLENAME}",
                "bundleVersion": "${DB_BUNDLEVERSION}"
            }
        }
    }
}

Just add a , after the line "seedEnvironments" : "development" and it's fixed.

ghost commented 1 year ago

I just checked both my backups and repository and there doesn't seem to be a .cfmigrations.json file in either of those 2 locations, which means this is something new.

Repository: https://bitbucket.org/ookma-kyi/ookma-kyi-core

Here is a link to the discussion of the error on the CFML Slack https://cfml.slack.com/archives/C06TSRXCJ/p1664303910313329 json error json error 2

elpete commented 1 year ago

Thanks for the issue. This is fixed in 4.0.1.