Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use Long as migration version #4297

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

Merged
merged 10 commits into from
Jun 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Sqlite318FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name
SqliteDialect().setup()
}

override val replaceRules: Array<Pair<String, String>> = arrayOf(
" INT NOT NULL" to " INTEGER NOT NULL",
)

companion object {
private val fixtures = arrayOf("src/test/fixtures_upsert_not_supported", "src/test/fixtures_sqlite_3_18")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
class Sqlite324FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules = arrayOf(
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ result_column ::= ( MULTIPLY
implements = "com.alecstrong.sql.psi.core.psi.SqlResultColumn"
override = true
}
select_stmt ::= SELECT [ DISTINCT | ALL ] {result_column} ( COMMA {result_column} ) * [ FROM {join_clause} ] [ WHERE <<expr '-1'>> ] [ GROUP BY <<expr '-1'>> ( COMMA <<expr '-1'>> ) * [ HAVING <<expr '-1'>> ] ] [ WINDOW window_name AS window_defn ( COMMA window_name AS window_defn ) * ] | VALUES {values_expression} ( COMMA {values_expression} ) * {
select_stmt ::= SELECT [ DISTINCT | ALL ] {result_column} ( COMMA {result_column} ) * [ FROM {join_clause} ] [ WHERE <<expr '-1'>> ] [{group_by}] [ HAVING <<expr '-1'>> ] [ WINDOW window_name AS window_defn ( COMMA window_name AS window_defn ) * ] | VALUES {values_expression} ( COMMA {values_expression} ) * {
extends = "com.alecstrong.sql.psi.core.psi.impl.SqlSelectStmtImpl"
implements = "com.alecstrong.sql.psi.core.psi.SqlSelectStmt"
override = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
class Sqlite325FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules = arrayOf(
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
class Sqlite330FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules = arrayOf(
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
class Sqlite333FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules = arrayOf(
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.File
class Sqlite335FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules = arrayOf(
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Sqlite338FixturesTest(name: String, fixtureRoot: File) : FixturesTest(name
"ORDER or WHERE expected" to "ORDER, WHERE or WINDOW expected",
"'(', ')', ',', '.', <binary like operator real>, BETWEEN or IN expected, got ','"
to "'(', ')', ',', '.', <binary like operator real>, <json binary operator real>, BETWEEN or IN expected, got ','",
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import java.io.File

@RunWith(Parameterized::class)
class JsonModuleTest(name: String, fixtureRoot: File) : FixturesTest(name, fixtureRoot) {
override val replaceRules: Array<Pair<String, String>> = arrayOf(
" INT NOT NULL" to " INTEGER NOT NULL",
)

override fun setupDialect() {
SqliteDialect().setup()
JsonModule().setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class AndroidSqliteDriver private constructor(
open class Callback(
private val schema: SqlSchema<QueryResult.Value<Unit>>,
private vararg val callbacks: AfterVersion,
) : SupportSQLiteOpenHelper.Callback(schema.version) {
) : SupportSQLiteOpenHelper.Callback(
if (schema.version > Int.MAX_VALUE) error("Schema version is larger than Int.MAX_VALUE: ${schema.version}.") else schema.version.toInt(),
) {

override fun onCreate(db: SupportSQLiteDatabase) {
schema.create(AndroidSqliteDriver(openHelper = null, database = db, cacheSize = 1))
Expand All @@ -197,8 +199,8 @@ class AndroidSqliteDriver private constructor(
) {
schema.migrate(
AndroidSqliteDriver(openHelper = null, database = db, cacheSize = 1),
oldVersion,
newVersion,
oldVersion.toLong(),
newVersion.toLong(),
*callbacks,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.test.assertTrue
abstract class DriverTest {
protected lateinit var driver: SqlDriver
protected val schema = object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand Down Expand Up @@ -52,8 +52,8 @@ abstract class DriverTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
) = QueryResult.Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class QueryTest {
@BeforeTest fun setup() {
driver = setupDatabase(
schema = object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand All @@ -47,8 +47,8 @@ abstract class QueryTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
): QueryResult.Value<Unit> {
// No-op.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ abstract class TransacterTest {
@BeforeTest fun setup() {
val driver = setupDatabase(
object : SqlSchema<QueryResult.Value<Unit>> {
override val version = 1
override val version = 1L
override fun create(driver: SqlDriver): QueryResult.Value<Unit> = QueryResult.Unit
override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
): QueryResult.Value<Unit> = QueryResult.Unit
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ class NativeSqliteDriver(
) : this(
configuration = DatabaseConfiguration(
name = name,
version = schema.version,
version = if (schema.version > Int.MAX_VALUE) error("Schema version is larger than Int.MAX_VALUE: ${schema.version}.") else schema.version.toInt(),
create = { connection -> wrapConnection(connection) { schema.create(it) } },
upgrade = { connection, oldVersion, newVersion ->
wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion, *callbacks) }
wrapConnection(connection) { schema.migrate(it, oldVersion.toLong(), newVersion.toLong(), *callbacks) }
},
).let(onConfiguration),
maxReaderConnections = maxReaderConnections,
Expand Down Expand Up @@ -256,12 +256,12 @@ fun inMemoryDriver(schema: SqlSchema<QueryResult.Value<Unit>>): NativeSqliteDriv
DatabaseConfiguration(
name = null,
inMemory = true,
version = schema.version,
version = if (schema.version > Int.MAX_VALUE) error("Schema version is larger than Int.MAX_VALUE: ${schema.version}.") else schema.version.toInt(),
create = { connection ->
wrapConnection(connection) { schema.create(it) }
},
upgrade = { connection, oldVersion, newVersion ->
wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion) }
wrapConnection(connection) { schema.migrate(it, oldVersion.toLong(), newVersion.toLong()) }
},
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class LazyDriverBaseTest {

protected fun defaultSchema(): SqlSchema<QueryResult.Value<Unit>> {
return object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand Down Expand Up @@ -68,8 +68,8 @@ abstract class LazyDriverBaseTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
) = QueryResult.Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ abstract class BaseConcurrencyTest {
): SqlDriver {
return setupDatabase(
schema = object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand All @@ -130,8 +130,8 @@ abstract class BaseConcurrencyTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
) = QueryResult.Unit
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JsDriverTest {
}

private val schema = object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand Down Expand Up @@ -59,8 +59,8 @@ class JsDriverTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
): QueryResult.Value<Unit> {
// No-op.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class JsQueryTest {
}

private val schema = object : SqlSchema<QueryResult.Value<Unit>> {
override val version: Int = 1
override val version: Long = 1

override fun create(driver: SqlDriver): QueryResult.Value<Unit> {
driver.execute(
Expand All @@ -45,8 +45,8 @@ class JsQueryTest {

override fun migrate(
driver: SqlDriver,
oldVersion: Int,
newVersion: Int,
oldVersion: Long,
newVersion: Long,
vararg callbacks: AfterVersion,
): QueryResult.Value<Unit> {
// No-op.
Expand Down
Loading