Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always create the database implementation #3540

Merged
merged 1 commit into from Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -174,6 +174,7 @@ class SqlDelightEnvironment(
output = writer,
includeAll = true,
)
SqlDelightCompiler.writeImplementations(module, migrationFile, moduleName, writer)
}
logger("----- END ${migrationFile.name} in $timeTaken ms ------")
}
Expand Down
Expand Up @@ -72,7 +72,7 @@ object SqlDelightCompiler {

fun writeImplementations(
module: Module,
sourceFile: SqlDelightQueriesFile,
sourceFile: SqlDelightFile,
implementationFolder: String,
output: FileAppender,
) {
Expand Down
@@ -0,0 +1,26 @@
buildscript {
apply from: "${projectDir.absolutePath}/../buildscript.gradle"
}

apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'app.cash.sqldelight'

repositories {
maven {
url "file://${projectDir.absolutePath}/../../../../build/localMaven"
}
mavenCentral()
}

sqldelight {
NoQueries {
packageName = "app.cash.sqldelight.derive.schema.from.migrations.no.queries"
deriveSchemaFromMigrations = true
}
}

dependencies {
implementation libs.sqliteJdbc
implementation "app.cash.sqldelight:sqlite-driver:${app.cash.sqldelight.VersionKt.VERSION}"
implementation libs.truth
}
@@ -0,0 +1,9 @@
apply from: "../settings.gradle"

rootProject.name = 'derive-schema-no-queries'

buildCache {
local {
directory = new File(rootDir, 'build-cache')
}
}
@@ -0,0 +1,5 @@
CREATE TABLE person (
_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
);
@@ -0,0 +1,18 @@
package app.cash.sqldelight.integration

import app.cash.sqldelight.derive.schema.from.migrations.no.queries.NoQueries
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import org.junit.After
import org.junit.Test
import java.io.File

class IntegrationTests {
@After fun after() {
File("test.db").delete()
}

@Test fun `creating db works without query files`() {
val database = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
NoQueries.Schema.create(database)
}
}
Expand Up @@ -282,4 +282,13 @@ class IntegrationTest {
val result = runner.build()
assertThat(result.output).contains("BUILD SUCCESSFUL")
}

@Test fun `deriveSchemaFromMigrations creates a db without queries`() {
val runner = GradleRunner.create()
.withCommonConfiguration(File("src/test/derive-schema-no-queries"))
.withArguments("clean", "build", "--stacktrace")

val result = runner.build()
assertThat(result.output).contains("BUILD SUCCESSFUL")
}
}