-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SpannerEmulatorDatabaseRule to take in a Liquibase changelog.
This also drops the unused wrapper executable around the Spanner emulator.
- Loading branch information
Showing
16 changed files
with
218 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
alias( | ||
name = "core", | ||
actual = "@maven//:org_liquibase_liquibase_core", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
alias( | ||
name = "spanner", | ||
actual = "@maven//:com_google_cloudspannerecosystem_liquibase_spanner", | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/org/wfanet/measurement/common/ClassLoaderResources.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2022 The Cross-Media Measurement Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.wfanet.measurement.common | ||
|
||
import java.net.URI | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
private val ZIP_FS_PROPERTIES: Map<String, Any> = mapOf("create" to "true") | ||
|
||
/** | ||
* Returns a [Path] to the resource with the specified [name] within a JAR. | ||
* | ||
* This initializes the [java.io.FileSystem] for the | ||
* [zip file system provider](https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html) | ||
* . | ||
*/ | ||
fun ClassLoader.getJarResourcePath(name: String): Path? { | ||
val resourceUri: URI = getResource(name)?.toURI() ?: return null | ||
|
||
// Initialize zip FileSystem. | ||
FileSystems.newFileSystem(resourceUri, ZIP_FS_PROPERTIES) | ||
|
||
return Paths.get(resourceUri) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/org/wfanet/measurement/common/db/liquibase/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
kt_jvm_library( | ||
name = "liquibase", | ||
srcs = glob(["*.kt"]), | ||
deps = ["//imports/java/liquibase:core"], | ||
) |
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/org/wfanet/measurement/common/db/liquibase/FileSystemResourceAccessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2022 The Cross-Media Measurement Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.wfanet.measurement.common.db.liquibase | ||
|
||
import java.lang.UnsupportedOperationException | ||
import java.nio.file.FileSystem | ||
import java.nio.file.Files | ||
import java.util.SortedSet | ||
import liquibase.resource.AbstractResourceAccessor | ||
import liquibase.resource.InputStreamList | ||
|
||
/** | ||
* [liquibase.resource.ResourceAccessor] which accesses resources from the given [fileSystem]. | ||
* | ||
* Note that this is not the same as [liquibase.resource.FileSystemResourceAccessor], which only | ||
* accesses files from [java.io.DefaultFileSystem] or from provided archives. | ||
*/ | ||
internal class FileSystemResourceAccessor(private val fileSystem: FileSystem) : | ||
AbstractResourceAccessor() { | ||
/** | ||
* @see [AbstractResourceAccessor.openStreams] | ||
* | ||
* This implementation does not handle archives. Paths are expected to be valid for [fileSystem]. | ||
*/ | ||
override fun openStreams(relativeTo: String?, streamPath: String?): InputStreamList { | ||
requireNotNull(streamPath) | ||
|
||
val path = | ||
if (relativeTo == null) { | ||
fileSystem.getPath(streamPath) | ||
} else { | ||
fileSystem.getPath(relativeTo).resolve(streamPath) | ||
} | ||
|
||
return InputStreamList(path.toUri(), Files.newInputStream(path)) | ||
} | ||
|
||
override fun list( | ||
relativeTo: String?, | ||
path: String?, | ||
recursive: Boolean, | ||
includeFiles: Boolean, | ||
includeDirectories: Boolean, | ||
): SortedSet<String> { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun describeLocations(): SortedSet<String> { | ||
throw UnsupportedOperationException() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/org/wfanet/measurement/common/db/liquibase/Liquibase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2022 The Cross-Media Measurement Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.wfanet.measurement.common.db.liquibase | ||
|
||
import java.nio.file.Path | ||
import java.sql.Connection | ||
import liquibase.Liquibase | ||
import liquibase.database.DatabaseFactory | ||
import liquibase.database.jvm.JdbcConnection | ||
|
||
object Liquibase { | ||
fun fromPath(connection: Connection, changelogPath: Path): Liquibase { | ||
return Liquibase( | ||
changelogPath.toString(), | ||
FileSystemResourceAccessor(changelogPath.fileSystem), | ||
DatabaseFactory.getInstance().findCorrectDatabaseImplementation(JdbcConnection(connection)) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.