Skip to content

SQL Server: migrate dev (and db push) does not create a database #8058

Closed
prisma/prisma-engines
#2140

Description

@janpio

This is the error message when you try to migrate a database that does not exist on SQL Server:

C:\Users\Jan\Documents\throwaway\sqlServerCycles>npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db" - SQL Server

Error: Migration engine error:
Performing a TLS handshake
Trusting the server certificate without validation.
TLS handshake successful
Turning TLS off after a login. All traffic from here on is not encrypted.
Cannot open database "mydb" requested by the login. The login failed.
Database error
Database does not exist: mydb

(We should probably have tests for all databases that ensure this works)

Activity

  1. added
    topic: sql server
    topic: prisma migrate dev
    on Jul 4, 2021
  2. changed the title [-]SQL Server: `migrate dev` does not create a database[/-] [+]SQL Server: `migrate dev` (and `db push`) does not create a database[/+] on Jul 4, 2021
  3. added
    bug/1-unconfirmed
    kind/bug
    on Jul 4, 2021
  4. tomhoule commented on Jul 5, 2021

    @tomhoule
    Contributor

    @Jolg42 I think the new error logging code has a problem, this is not the expected error message. I'll try to look into this today.

  5. tomhoule commented on Jul 5, 2021

    @tomhoule
    Contributor

    (looking into it currently)

  6. added this to the 2.27.0 milestone on Jul 6, 2021
  7. Jolg42 commented on Jul 6, 2021

    @Jolg42
  8. janpio commented on Jul 6, 2021

    @janpio
    Author
  9. 7 remaining items

  10. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Jul 28, 2021
  11. Jolg42 commented on Aug 5, 2021

    @Jolg42
    Contributor

    Error with DEBUG="*"

    Error: Error: Migration engine error:
    Performing a TLS handshake
    Trusting the server certificate without validation.
    TLS handshake successful
    Turning TLS off after a login. All traffic from here on is not encrypted.
    Cannot open database "hellomssql" requested by the login. The login failed.
    Database error
    Database does not exist: hellomssql
    
        at Object.canConnectToDatabase (/Users/j42/Dev/prisma-esbuild/packages/sdk/dist/migrateEngineCommands.js:94:15)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
        at Object.ensureDatabaseExists (/Users/j42/Dev/prisma-esbuild/packages/migrate/src/utils/ensureDatabaseExists.ts:118:22)
        at DbPush.parse (/Users/j42/Dev/prisma-esbuild/packages/migrate/src/commands/DbPush.ts:116:26)
        at main (/Users/j42/Dev/prisma-esbuild/packages/migrate/src/bin.ts:80:18)
    
  12. Jolg42 commented on Aug 5, 2021

    @Jolg42
    Contributor

    Should be fixed when prisma/prisma-engines#2133 drops

  13. Jolg42 commented on Aug 5, 2021

    @Jolg42
  14. assigned and unassigned on Aug 5, 2021
  15. added
    tech/engines/migration engine
    on Aug 6, 2021
  16. Jolg42 commented on Aug 9, 2021

    @Jolg42
    Contributor

    Just played with the CLI, needed to fix some logic but now I get this

    In 2.29.0-dev.42 (and soon in 2.29)

    First push env DEBUG="*" npx prisma@dev db push

    Prisma schema loaded from prisma/schema.prisma
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/35364/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +0ms
    Datasource "my_db" - SQL Server
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/35364/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +431ms
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/35364/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +18ms
    Error: Error: Migration engine error:
    Performing a TLS handshake
    Trusting the server certificate without validation.
    TLS handshake successful
    Turning TLS off after a login. All traffic from here on is not encrypted.
    Database change from 'master' to 'master'
    Changed database context to 'master'.
    SQL collation change from None to windows-1252/windows-1252
    Microsoft SQL Server version 4077846543
    Packet size change from '4096' to '4096'
    Starting a mssql connection.
    Performing a TLS handshake
    Trusting the server certificate without validation.
    TLS handshake successful
    Turning TLS off after a login. All traffic from here on is not encrypted.
    Database change from 'sdfsd2' to 'master'
    Changed database context to 'sdfsd2'.
    SQL collation change from None to windows-1252/windows-1252
    Microsoft SQL Server version 4077846543
    Packet size change from '4096' to '4096'
    Starting a mssql connection.
    The specified schema name "dbo" either does not exist or you do not have permission to use it.
    Database error
    Error querying the database: 'The specified schema name "dbo" either does not exist or you do not have permission to use it.' on server 5af6d931d9fb executing  on line 1 (code: 2760, state: 1, class: 16)
    
        at createDatabase2 (/Users/j42/.npm/_npx/35364/lib/node_modules/prisma/build/index.js:43020:17)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
        at async ensureDatabaseExists (/Users/j42/.npm/_npx/35364/lib/node_modules/prisma/build/index.js:64079:11)
        at async _DbPush.parse (/Users/j42/.npm/_npx/35364/lib/node_modules/prisma/build/index.js:67446:28)
        at async main (/Users/j42/.npm/_npx/35364/lib/node_modules/prisma/build/index.js:114233:18)
    

    Second push env DEBUG="*" npx prisma@dev db push

    Prisma schema loaded from prisma/schema.prisma
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/36090/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +0ms
    Datasource "my_db" - SQL Server
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/36090/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +353ms
      prisma:getConfig Using Query Engine Binary at: /Users/j42/.npm/_npx/36090/lib/node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin +17ms
      prisma:migrateEngine:rpc starting migration engine with binary: /Users/j42/.npm/_npx/36090/lib/node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin +0ms
      prisma:migrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"schemaPush","params":{"force":false,"schema":"datasource my_db {\n  provider = \"sqlserver\"\n  url      = \"sqlserver://localhost:1433;database=sdfsd2;user=SA;password=Pr1sm4_Pr1sm4;trustServerCertificate=true;\"\n}\n\n// datasource my_db {\n//   provider = \"postgresql\"\n//   url      = \"postgres://prisma:prisma@localhost:5432/yoloooooooo\"\n// }\n\nmodel Blog {\n  id          Int @id\n  viewCount20 Int\n}\n"}} +4ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.523892+00:00","level":"INFO","fields":{"message":"Starting migration engine RPC server","git_hash":"36af3f44e00e1f6ae2ef08ebf105fb0120b43a66"},"target":"migration_engine"} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.529894+00:00","level":"INFO","fields":{"message":"Performing a TLS handshake"},"target":"tiberius::client::connection","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +6ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.529930+00:00","level":"WARN","fields":{"message":"Trusting the server certificate without validation."},"target":"tiberius::client::connection","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.548005+00:00","level":"INFO","fields":{"message":"TLS handshake successful"},"target":"tiberius::client::connection","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +18ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.548102+00:00","level":"WARN","fields":{"message":"Turning TLS off after a login. All traffic from here on is not encrypted."},"target":"tiberius::client::connection","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.554962+00:00","level":"INFO","fields":{"message":"Database change from 'sdfsd2' to 'master'"},"target":"tiberius::tds::stream::token","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +7ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.554996+00:00","level":"INFO","fields":{"message":"Changed database context to 'sdfsd2'."},"target":"tiberius::tds::stream::token","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.555011+00:00","level":"INFO","fields":{"message":"SQL collation change from None to windows-1252/windows-1252"},"target":"tiberius::tds::stream::token","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.555025+00:00","level":"INFO","fields":{"message":"Microsoft SQL Server\u0000\u0000 version 4077846543"},"target":"tiberius::tds::stream::token","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.555034+00:00","level":"INFO","fields":{"message":"Packet size change from '4096' to '4096'"},"target":"tiberius::tds::stream::token","span":{"name":"new_connection"},"spans":[{"name":"new_connection"}]} +0ms
      prisma:migrateEngine:stderr {"timestamp":"2021-08-10T08:58:37.555078+00:00","level":"INFO","fields":{"message":"Starting a mssql connection."},"target":"quaint::single"} +0ms
    
    🚀  Your database is now in sync with your schema. Done in 364ms
    

    So something is created but we cannot use it right away somehow?

  17. Jolg42 commented on Aug 10, 2021

    @Jolg42
    Contributor
  18. Jolg42 commented on Aug 10, 2021

    @Jolg42
    Contributor

    Fixed in dev 2.29.0-dev.49 and will be part of 2.29.0 today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtech/engines/migration enginetopic: prisma migrate devtopic: sql server

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions