Skip to content

Commit

Permalink
chore(migrate): remove sqlite check now performed engine-side (#12770)
Browse files Browse the repository at this point in the history
* chore(migrate): remove sqlite check now performed engine-side

See prisma/prisma-engines#2836 for the details
on the engines side of things. The consequence of that PR is that we are
now doing that check in engines, and doing it in more cases than the
check removed in this PR.

* .

* chore(migrate): remove sqlite check now performed engine-side

See prisma/prisma-engines#2836 for the details
on the engines side of things. The consequence of that PR is that we are
now doing that check in engines, and doing it in more cases than the
check removed in this PR.

* .

* cli: updated snapshot in doctor

* sdk: updated snapshots

* migrate: updated snapshots

Co-authored-by: Alberto Schiabel <skiabo97@gmail.com>
Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 25, 2022
1 parent f2391f2 commit 22f6f51
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/Doctor.test.ts
Expand Up @@ -17,7 +17,7 @@ it('should fail when db is missing', async () => {
ctx.fixture('schema-db-out-of-sync')
ctx.fs.remove('dev.db')
const result = Doctor.new().parse([])
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`P1003: SQLite database file doesn't exist`)
await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`P1003: Database dev.db does not exist at dev.db`)
})

it('should fail when Prisma schema is missing', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/src/__tests__/MigrateResolve.test.ts
Expand Up @@ -49,7 +49,7 @@ describe('sqlite', () => {
it('should fail if no sqlite db - empty schema', async () => {
ctx.fixture('schema-only-sqlite')
const result = MigrateResolve.new().parse(['--schema=./prisma/empty.prisma', '--applied=something_applied'])
await expect(result).rejects.toMatchInlineSnapshot(`P1003: SQLite database file doesn't exist`)
await expect(result).rejects.toMatchInlineSnapshot(`P1003: Database dev.db does not exist at dev.db`)

expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(`
Prisma schema loaded from prisma/empty.prisma
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/src/__tests__/MigrateStatus.test.ts
Expand Up @@ -38,7 +38,7 @@ describe('sqlite', () => {
await expect(result).resolves.toMatchInlineSnapshot(`
Database connection error:
P1003: SQLite database file doesn't exist
P1003: Database dev.db does not exist at dev.db
`)

expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(`
Expand Down
27 changes: 2 additions & 25 deletions packages/sdk/src/__tests__/migrateEngineCommands.test.ts
Expand Up @@ -4,7 +4,6 @@ import { credentialsToUri, uriToCredentials } from '../convertCredentials'
import {
canConnectToDatabase,
createDatabase,
doesSqliteDbExist,
dropDatabase,
execaCommand,
} from '../migrateEngineCommands'
Expand Down Expand Up @@ -33,28 +32,6 @@ describe('execaCommand', () => {
})
})

describe('doesSqliteDbExist', () => {
test('exist - sqlite:', async () => {
await expect(doesSqliteDbExist('sqlite:./introspection/blog.db', __dirname)).resolves.toEqual(true)
})

test('exist - file:', async () => {
await expect(doesSqliteDbExist('file:./introspection/blog.db', __dirname)).resolves.toEqual(true)
})

test('does not exist - sqlite:', async () => {
await expect(doesSqliteDbExist('sqlite:./doesnotexist.db', __dirname)).resolves.toEqual(false)
})

test('does not exist - file:', async () => {
await expect(doesSqliteDbExist('file:./doesnotexist.db', __dirname)).resolves.toEqual(false)
})

test('should error if no schemaDir and no schema found', async () => {
await expect(doesSqliteDbExist('file:./doesnotexist.db')).rejects.toThrowError()
})
})

describe('canConnectToDatabase', () => {
test('sqlite - can', async () => {
await expect(canConnectToDatabase('sqlite:./introspection/blog.db', __dirname)).resolves.toEqual(true)
Expand All @@ -64,7 +41,7 @@ describe('canConnectToDatabase', () => {
await expect(canConnectToDatabase('file:./doesnotexist.db')).resolves.toMatchInlineSnapshot(`
Object {
"code": "P1003",
"message": "SQLite database file doesn't exist",
"message": "Database doesnotexist.db does not exist at ./doesnotexist.db",
}
`)
})
Expand Down Expand Up @@ -166,7 +143,7 @@ describe('createDatabase', () => {

test('invalid database type', async () => {
await expect(createDatabase('invalid:somedburl')).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unknown protocol invalid:"`,
'"P1013: The provided database string is invalid. `invalid` is not a known connection URL scheme. Prisma cannot determine the connector. in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters."',
)
})

Expand Down
36 changes: 0 additions & 36 deletions packages/sdk/src/migrateEngineCommands.ts
Expand Up @@ -82,22 +82,6 @@ export async function canConnectToDatabase(
)
}

// hack to parse the protocol
const provider = protocolToConnectorType(`${connectionString.split(':')[0]}:`)

if (provider === 'sqlite') {
const sqliteExists = await doesSqliteDbExist(connectionString, cwd)
if (sqliteExists) {
return true
} else {
// is this necessary to do in CLI?
return {
code: 'P1003',
message: "SQLite database file doesn't exist",
}
}
}

try {
await execaCommand({
connectionString,
Expand Down Expand Up @@ -225,23 +209,3 @@ export async function execaCommand({
throw e
}
}

export async function doesSqliteDbExist(connectionString: string, schemaDir?: string): Promise<boolean> {
let filePath = connectionString

// this logic is duplicated
if (filePath.startsWith('file:')) {
filePath = filePath.slice(5)
} else if (filePath.startsWith('sqlite:')) {
filePath = filePath.slice(7)
}

const cwd = schemaDir || (await getSchemaDir())
if (!cwd) {
throw new Error(`Could not find schema.prisma in ${process.cwd()}`)
}

const absoluteTarget = path.resolve(cwd, filePath)

return exists(absoluteTarget)
}

0 comments on commit 22f6f51

Please sign in to comment.