planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.17k stars 35 forks source link

Error: direct DDL is disabled. Shadow Databases not helping, Development Branches not helping #158

Closed NLanese closed 8 months ago

NLanese commented 10 months ago

I made very slight changes to my prisma.schema which begins with the following information...

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider          = "mysql"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_URL")
  relationMode      = "prisma"
}

This db was made in 2021, using ONLY prisma generate and prisma migrate. However, both of those options are now failing as well, with the following error message

Error: P3014

Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases. Read more about the shadow database (and workarounds) at https://pris.ly/d/migrate-shadow

So I went back to PlanetScale and Prisma documentation. Both of which were really no help at all. The best I got was this off PlanetScales Prisma documentation... "Tip You'll see a ERROR 1105 (HY000): direct DDL is disabled message if you attempt to make schema changes in a production branch with safe migrations enabled. Instead, create a development branch, and make your changes there."

Expect that does me absolutely no good because I created a development branch and I'm still getting the exact same errors. So whenever I run prisma db push I get this...

Error: direct DDL is disabled
   0: sql_schema_connector::apply_migration::migration_step
           with step=AlterTable(AlterTable { table_ids: MigrationPair { previous: TableId(6), next: TableId(12) }, changes: [AddColumn { column_id: TableColumnId(113), has_virtual_default: false }] })
             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:21
   1: sql_schema_connector::apply_migration::apply_migration
             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:10
   2: schema_core::state::SchemaPush
             at schema-engine/core/src/state.rs:436

I am at my wits end trying to solve this, please assist!

mscoutermarsh commented 10 months ago

Hi @NLanese,

Could you double check that the DATABASE_URL is pointing towards your new development branch?

The reason I ask:

Error: direct DDL is disabled

Should only be returned by a production branch. Makes me think Prisma here isn't connected to the correct branch.

You could also go to the main branch page in the UI and disable safe migrations for your production branch.

If neither of these work, please let me know your org + database name and I'll take a look.

janpio commented 10 months ago

Note the parallel discussion about this problem in the Prisma repo: https://github.com/prisma/prisma/discussions/22588

NLanese commented 10 months ago

@mscoutermarsh I believe that was it! I did not realize different branches had different DATABSE_URLs! Now, I have pscale auth login to my account which has access to the Org which holds the database and its production and development branches. I am now getting an 'incorrect credentials' error when I run prisma db push How do I switch to be the user displayed in the 'Connect' section of this database, with username lkte0xromomngn1cab9l?

mscoutermarsh commented 10 months ago

prisma always uses whatever is set to DATABASE_URL in your environment. Are you updating your environment variable to match the correct connection string for the branch you want?

The pscale CLI does not do this for you. Unless you do something like this, pscale connect mydb mybranch --execute "prisma db push".

This command pscale connect, establishes a connection to the branch then exposes sets a DATABASE_URL. Once it is set, the --execute flag runs the prisma command.