Skip to content

Commit

Permalink
test(migrate): add provider switch test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Feb 15, 2021
1 parent 0445633 commit 0ca2ac1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
41 changes: 32 additions & 9 deletions src/packages/migrate/src/__tests__/MigrateDev.test.ts
Expand Up @@ -630,11 +630,11 @@ describe('sqlite', () => {

await expect(result).rejects.toMatchInlineSnapshot(`
⚠️ We found changes that cannot be executed:
⚠️ We found changes that cannot be executed:
• Step 0 Made the column \`fullname\` on table \`Blog\` required, but there are 1 existing NULL values.
• Step 0 Made the column \`fullname\` on table \`Blog\` required, but there are 1 existing NULL values.
`)
`)
expect(ctx.mocked['console.info'].mock.calls.join('\n'))
.toMatchInlineSnapshot(`
Prisma schema loaded from prisma/schema.prisma
Expand Down Expand Up @@ -693,10 +693,10 @@ describe('sqlite', () => {
expect(ctx.mocked['console.log'].mock.calls.join('\n'))
.toMatchInlineSnapshot(`
⚠️ There will be data loss when applying the migration:
⚠️ There will be data loss when applying the migration:
• You are about to drop the \`Blog\` table, which is not empty (2 rows).
`)
• You are about to drop the \`Blog\` table, which is not empty (2 rows).
`)
expect(ctx.mocked['console.error'].mock.calls).toMatchSnapshot()
})

Expand All @@ -717,10 +717,10 @@ describe('sqlite', () => {
expect(ctx.mocked['console.log'].mock.calls.join('\n'))
.toMatchInlineSnapshot(`
⚠️ There will be data loss when applying the migration:
⚠️ There will be data loss when applying the migration:
• You are about to drop the \`Blog\` table, which is not empty (2 rows).
`)
• You are about to drop the \`Blog\` table, which is not empty (2 rows).
`)
expect(ctx.mocked['console.error'].mock.calls).toMatchSnapshot()
})

Expand Down Expand Up @@ -879,6 +879,29 @@ describe('sqlite', () => {
This command only supports one seed file: Use \`seed.ts\`, \`.js\`, \`.sh\` or \`.go\`.
`)
})

it('provider switch: postgresql to sqlite', async () => {
ctx.fixture('provider-switch-postgresql-to-sqlite')

try {
await MigrateDev.new().parse(['--preview-feature'])
} catch (e) {
expect(e.code).toEqual('P3014')
expect(e.message).toContain('P3014')
expect(e.message).toContain('The datasource provider')
}

expect(ctx.mocked['console.info'].mock.calls.join('\n'))
.toMatchInlineSnapshot(`
Prisma schema loaded from prisma/schema.prisma
Datasource "my_db": SQLite database "dev.db" at "file:./dev.db"
SQLite database dev.db created at file:./dev.db
`)
expect(ctx.mocked['console.log'].mock.calls).toMatchSnapshot()
expect(ctx.mocked['console.error'].mock.calls).toMatchSnapshot()
})
})

describe('postgresql', () => {
Expand Down
Expand Up @@ -104,6 +104,10 @@ exports[`sqlite one seed file 4`] = ``;

exports[`sqlite provider array should fail 3`] = `Array []`;

exports[`sqlite provider switch: postgresql to sqlite 2`] = `Array []`;

exports[`sqlite provider switch: postgresql to sqlite 3`] = `Array []`;

exports[`sqlite removed applied migration and unapplied empty draft 3`] = ``;

exports[`sqlite removed applied migration and unapplied empty draft 4`] = ``;
Expand Down
@@ -0,0 +1 @@
-- CreateTable
@@ -1,2 +1,2 @@
# Please do not edit this file manually
provider = "sqlite"
provider = "postgresql"
@@ -0,0 +1,19 @@
// datasource my_db {
// provider = "postgresql"
// url = env("TEST_POSTGRES_URI_MIGRATE")
// }

datasource my_db {
provider = "sqlite"
url = "file:./dev.db"
}

generator client {
provider = "prisma-client-js"
output = "@prisma/client"
}

model Blog {
id Int @id
viewCount20 Int
}

0 comments on commit 0ca2ac1

Please sign in to comment.