Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Lift engine only supports new versions of MySQL ( >= 5.7 ). #38

Closed
Dajust opened this issue Jun 27, 2019 · 8 comments
Closed

Lift engine only supports new versions of MySQL ( >= 5.7 ). #38

Dajust opened this issue Jun 27, 2019 · 8 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Milestone

Comments

@Dajust
Copy link

Dajust commented Jun 27, 2019

Trying to prisma2 dev or Lift Up to older versions of MySQL threw this error.

 Error
   Error: Error in lift engine for rpc applyMigration:
     [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.
rs:83] self.pool.state() = State {
       connections: 10,
       idle_connections: 10,
   }
   [migration-engine/connectors/sql-migration-connector/src/lib.rs:273] format!("CREATE SCH
EMA IF NOT EXISTS `{}` DEFAULT CHARACTER SET latin1;" , &
           self . schema_name) = "CREATE SCHEMA IF NOT EXISTS `sql9296876` DEFAULT CHARACTE
R SET latin1;"
   [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs
:83] self.pool.state() = State {
       connections: 10,
       idle_connections: 10,
   }
   [migration-engine/connectors/sql-migration-connector/src/sql_migration_persistence.rs:38
] m.make_from(barrel_variant) = "CREATE TABLE sql9296876._Migration (revision INTEGER NOT N
ULL AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, datamodel TEXT NOT NULL, status TEXT NO
T NULL, applied INTEGER NOT NULL, rolled_back INTEGER NOT NULL, datamodel_steps TEXT NOT NU
LL, database_migration TEXT NOT NULL, errors TEXT NOT NULL, started_at datetime(3) NOT NULL
, finished_at datetime(3));"
   [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs
:83] self.pool.state() = State {
       connections: 10,
       idle_connections: 10,
   }
   [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs
:83] self.pool.state() = State {
       connections: 10,
       idle_connections: 10,
   }
   [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs
:83] self.pool.state() = State {
       connections: 10,
       idle_connections: 10,
   }
   [/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs
:158] visitor::Mysql::build(q) = (
       "SELECT `sql9296876`.`_Migration`.* FROM `sql9296876`.`_Migration` WHERE `status` = 
? ORDER BY `revision` DESC",
       [
           Text(
               "MigrationSuccess",
           ),
       ],
   )
   thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: QueryError(MySql
Error { ERROR 1146 (42S02): Table 'sql9296876._Migration' doesn't exist }

   stack backtrace:
      0: failure::backtrace::internal::InternalBacktrace::new::h84e0252f893b7b0e (0x5645aae
9c4f0)
      1: <failure::backtrace::Backtrace as core::default::Default>::default::hd8f6c25d93ae9
c26 (0x5645aae9c6a0)

Here, Lift is using the expanded fractional seconds syntax to create fields
started_at datetime(3) NOT NULL, finished_at datetime(3) on the _Migration table.

But because this syntax was only introduced in version 5.6.4, older versions will see that as syntax error and will fail to create the _Migration table.Thus, when Lift tried to query the _Migration table it throws the above error because the table does not exist.

If supporting only newer versions is the plan, this should be properly documented. Else, please add support for older versions.

@Dajust Dajust changed the title Lift engine only supports new versions of MySQL ( > 5.6.4 ). Lift engine only supports new versions of MySQL ( >= 5.7 ). Jun 27, 2019
@Gbahaa
Copy link

Gbahaa commented Jun 27, 2019

I am receiving a similar error reported in another issue with (mysql 5.7.24)

@Dajust
Copy link
Author

Dajust commented Jun 28, 2019

@Gbahaa what is the error message you got? The root cause of Lift errors are usually printed in a line that begins with something like thread 'main' panicked at '... on the error message. For this issue that's the line:

 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: QueryError(MySql
Error { ERROR 1146 (42S02): Table 'sql9296876._Migration' doesn't exist }

Plain enough to start tracing the bug, I guess, at least it fixed the issue for me. 😄
If you can find such line please show what it says.

@Gbahaa
Copy link

Gbahaa commented Jun 28, 2019

thanks for that. This is the error I got

thread 'main' panicked at 'The model Place already exists in this data model. It is not possible to create it once more.'

It tries to create models again

@Dajust
Copy link
Author

Dajust commented Jun 28, 2019

No problem, that's a know issue. you might want to follow the temporal fix on the referenced issue above to fix it.

@divyenduz divyenduz added the bug/1-repro-available A reproduction exists and needs to be confirmed. label Jun 28, 2019
@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. and removed bug/1-repro-available A reproduction exists and needs to be confirmed. labels Jun 28, 2019
@pantharshit00
Copy link
Contributor

I can reproduce this even with MySQL 5.7. I need to remove _Migrations table every time as a workaround.

Bug report

Failed applyMigration at 2019-06-28T15:32:27.467Z

RPC Input One Line

{"id":1,"jsonrpc":"2.0","method":"applyMigration","params":{"projectInfo":"","force":true,"migrationId":"watch-20190628210227","steps":[{"stepType":"CreateModel","name":"User","embedded":false},{"stepType":"CreateField","model":"User","name":"id","type":{"Base":"String"},"arity":"required","isUnique":false,"id":{"strategy":"Auto","sequence":null},"default":{"Expression":["cuid","String",[]]}},{"stepType":"CreateField","model":"User","name":"username","type":{"Base":"String"},"arity":"required","isUnique":true},{"stepType":"CreateField","model":"User","name":"password","type":{"Base":"String"},"arity":"required","isUnique":false},{"stepType":"CreateField","model":"User","name":"age","type":{"Base":"Int"},"arity":"required","isUnique":false,"default":{"Int":18}},{"stepType":"CreateField","model":"User","name":"priviliages","type":{"Enum":"Priviliages"},"arity":"required","isUnique":false},{"stepType":"CreateEnum","name":"Priviliages","values":["ADMIN","USER"]}],"sourceConfig":"datasource db {\n  provider = \"mysql\"\n  url      = \"mysql://root:Harshit00@localhost:3306/issue_60\"\n}\n\ngenerator photon {\n  provider = \"photonjs\"\n}\n\nenum Priviliages {\n  ADMIN\n  USER\n}\n\nmodel User {\n  id          String      @id @default(cuid())\n  username    String      @unique\n  password    String\n  age         Int         @default(18)\n  priviliages Priviliages\n}"}}

RPC Input Readable

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "applyMigration",
  "params": {
    "projectInfo": "",
    "force": true,
    "migrationId": "watch-20190628210227",
    "steps": [
      {
        "stepType": "CreateModel",
        "name": "User",
        "embedded": false
      },
      {
        "stepType": "CreateField",
        "model": "User",
        "name": "id",
        "type": {
          "Base": "String"
        },
        "arity": "required",
        "isUnique": false,
        "id": {
          "strategy": "Auto",
          "sequence": null
        },
        "default": {
          "Expression": [
            "cuid",
            "String",
            []
          ]
        }
      },
      {
        "stepType": "CreateField",
        "model": "User",
        "name": "username",
        "type": {
          "Base": "String"
        },
        "arity": "required",
        "isUnique": true
      },
      {
        "stepType": "CreateField",
        "model": "User",
        "name": "password",
        "type": {
          "Base": "String"
        },
        "arity": "required",
        "isUnique": false
      },
      {
        "stepType": "CreateField",
        "model": "User",
        "name": "age",
        "type": {
          "Base": "Int"
        },
        "arity": "required",
        "isUnique": false,
        "default": {
          "Int": 18
        }
      },
      {
        "stepType": "CreateField",
        "model": "User",
        "name": "priviliages",
        "type": {
          "Enum": "Priviliages"
        },
        "arity": "required",
        "isUnique": false
      },
      {
        "stepType": "CreateEnum",
        "name": "Priviliages",
        "values": [
          "ADMIN",
          "USER"
        ]
      }
    ],
    "sourceConfig": "datasource db {\n  provider = \"mysql\"\n  url      = \"mysql://root:Harshit00@localhost:3306/issue_60\"\n}\n\ngenerator photon {\n  provider = \"photonjs\"\n}\n\nenum Priviliages {\n  ADMIN\n  USER\n}\n\nmodel User {\n  id          String      @id @default(cuid())\n  username    String      @unique\n  password    String\n  age         Int         @default(18)\n  priviliages Priviliages\n}"
  }
}

RPC Response

null

Stack Trace

[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[migration-engine/connectors/sql-migration-connector/src/lib.rs:273] format!("CREATE SCHEMA IF NOT EXISTS `{}` DEFAULT CHARACTER SET latin1;" , &
        self . schema_name) = "CREATE SCHEMA IF NOT EXISTS `issue_60` DEFAULT CHARACTER SET latin1;"
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[migration-engine/connectors/sql-migration-connector/src/sql_migration_persistence.rs:38] m.make_from(barrel_variant) = "CREATE TABLE issue_60._Migration (revision INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name TEXT NOT NULL, datamodel TEXT NOT NULL, status TEXT NOT NULL, applied INTEGER NOT NULL, rolled_back INTEGER NOT NULL, datamodel_steps TEXT NOT NULL, database_migration TEXT NOT NULL, errors TEXT NOT NULL, started_at datetime(3) NOT NULL, finished_at datetime(3));"
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:158] visitor::Mysql::build(q) = (
    "SELECT `issue_60`.`_Migration`.* FROM `issue_60`.`_Migration` WHERE `status` = ? ORDER BY `revision` DESC",
    [
        Text(
            "MigrationSuccess"
        )
    ]
)
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:83] self.pool.state() = State {
    connections: 10,
    idle_connections: 10
}
[/var/root/.cargo/git/checkouts/prisma-query-a8c45647247f5d6d/5a95ce6/src/connector/mysql.rs:158] visitor::Mysql::build(q) = (
    "SELECT `issue_60`.`_Migration`.* FROM `issue_60`.`_Migration` WHERE `status` = ? ORDER BY `revision` DESC",
    [
        Text(
            "MigrationSuccess"
        )
    ]
)
thread 'main' panicked at 'The model User already exists in this Datamodel. It is not possible to create it once more.', migration-engine/core/src/migration/datamodel_calculator.rs:59:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::continue_panic_fmt
   6: std::panicking::begin_panic_fmt
   7: <migration_core::migration::datamodel_calculator::DataModelCalculatorImpl as migration_core::migration::datamodel_calculator::DataModelCalculator>::infer
   8: <migration_core::commands::apply_migration::ApplyMigrationCommand as migration_core::commands::command::MigrationCommand>::execute
   9: <F as jsonrpc_core::calls::RpcMethodSimple>::call
  10: <F as jsonrpc_core::calls::RpcMethod<T>>::call
  11: <futures::future::lazy::Lazy<F, R> as futures::future::Future>::poll
  12: <futures::future::then::Then<A, B, F> as futures::future::Future>::poll
  13: <futures::future::map::Map<A, F> as futures::future::Future>::poll
  14: <futures::future::either::Either<A, B> as futures::future::Future>::poll
  15: futures::task_impl::std::set
  16: <std::thread::local::LocalKey<T>>::with
  17: futures::future::Future::wait
  18: <jsonrpc_core::io::IoHandler<M>>::handle_request_sync
  19: migration_core::rpc_api::RpcApi::handle
  20: migration_engine::main
  21: std::rt::lang_start::{{closure}}
  22: std::panicking::try::do_call
  23: __rust_maybe_catch_panic
  24: std::rt::lang_start_internal
  25: main

@Dajust
Copy link
Author

Dajust commented Jun 28, 2019

@pantharshit00 your issue is different. It's a flaw on the current modality of prisma2 dev reported here. It occurs only on subsequent attempts to run prisma2 dev.

However, this very issues occurs even when there's no _Migration table on the DB. And it only occurs on earlier versions of MySQL.

@pantharshit00
Copy link
Contributor

Oh ok. Thanks for the heads up.

I can confirm this behaviour as well.

@mavilein
Copy link
Member

mavilein commented Aug 5, 2019

I changed our CI tests to use MySQL 5.6 and the tests ran successfully on alpha.. Considering this fixed now. Happy to reopen if this not the case. 🙏

@mavilein mavilein closed this as completed Aug 5, 2019
@janpio janpio added this to the Preview 6 milestone Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

7 participants