Privatize db migration scripts (#6800)

* Privatize migration scripts

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Robert Autenrieth 2020-07-21 11:16:42 +02:00 committed by GitHub
parent 6bf1eb19ae
commit 8732c51392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 75 additions and 70 deletions

View File

@ -3,7 +3,7 @@
// Note: package name must correspond exactly to the flyway 'locations' setting, which defaults to
// 'db.migration.h2database' for h2database migrations
package db.migration.h2database
package com.daml.platform.db.migration.h2database
import java.sql.Connection
@ -13,10 +13,10 @@ import com.daml.lf.transaction.Node.NodeCreate
import com.daml.ledger.EventId
import com.daml.lf.data.Ref.LedgerString
import com.daml.platform.store.Conversions._
import db.migration.translation.TransactionSerializer
import com.daml.platform.db.migration.translation.TransactionSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V5_1__Populate_Event_Data extends BaseJavaMigration {
private[migration] class V5_1__Populate_Event_Data extends BaseJavaMigration {
val SELECT_TRANSACTIONS =
"select distinct le.transaction_id, le.transaction from contracts c join ledger_entries le on c.transaction_id = le.transaction_id"

View File

@ -3,7 +3,7 @@
// Note: package name must correspond exactly to the flyway 'locations' setting, which defaults to
// 'db.migration.postgres' for postgres migrations
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import java.sql.Connection
@ -13,10 +13,10 @@ import com.daml.lf.transaction.Node.NodeCreate
import com.daml.ledger.EventId
import com.daml.lf.data.Ref
import com.daml.platform.store.Conversions._
import db.migration.translation.TransactionSerializer
import com.daml.platform.db.migration.translation.TransactionSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V10_1__Populate_Event_Data extends BaseJavaMigration {
private[migration] class V10_1__Populate_Event_Data extends BaseJavaMigration {
val SELECT_TRANSACTIONS =
"select distinct le.transaction_id, le.transaction from contracts c join ledger_entries le on c.transaction_id = le.transaction_id"

View File

@ -1,15 +1,15 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import com.daml.ledger.participant.state.v1.Offset
import com.daml.lf.data.Ref
import db.migration.postgres.v25_backfill_participant_events.V25TransactionsWriter
import db.migration.translation.TransactionSerializer
import com.daml.platform.db.migration.postgres.v25_backfill_participant_events.V25TransactionsWriter
import com.daml.platform.db.migration.translation.TransactionSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V25__Backfill_Participant_Events extends BaseJavaMigration {
private[migration] class V25__Backfill_Participant_Events extends BaseJavaMigration {
val SELECT_TRANSACTIONS = "select * from ledger_entries where typ='transaction'"

View File

@ -1,15 +1,15 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import java.io.ByteArrayInputStream
import com.daml.platform.store.serialization.ValueSerializer
import db.migration.translation.ContractSerializer
import com.daml.platform.db.migration.translation.ContractSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V26_1__Fill_create_argument extends BaseJavaMigration {
private[migration] class V26_1__Fill_create_argument extends BaseJavaMigration {
// left join on contracts to make sure to include divulged contracts
private val SELECT_CONTRACT_DATA =

View File

@ -1,11 +1,11 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
final class V28__Fix_key_hashes extends BaseJavaMigration {
private[migration] final class V28__Fix_key_hashes extends BaseJavaMigration {
override def migrate(context: Context): Unit = {
// Content of migration moved to V32_1 (see https://github.com/digital-asset/daml/issues/6017)

View File

@ -1,15 +1,15 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import com.daml.ledger.participant.state.v1.Offset
import com.daml.lf.data.Ref
import db.migration.postgres.v29_fix_participant_events.V29TransactionsWriter
import db.migration.translation.TransactionSerializer
import com.daml.platform.db.migration.postgres.v29_fix_participant_events.V29TransactionsWriter
import com.daml.platform.db.migration.translation.TransactionSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V29__Fix_participant_events extends BaseJavaMigration {
private[migration] class V29__Fix_participant_events extends BaseJavaMigration {
val TRUNCATE_PARTICIPANT_EVENTS =
"truncate table participant_events cascade"

View File

@ -3,7 +3,7 @@
// Note: package name must correspond exactly to the flyway 'locations' setting, which defaults to
// 'db.migration.postgres' for postgres migrations
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import java.io.InputStream
import java.sql.Connection
@ -29,7 +29,7 @@ import com.daml.platform.store.Conversions._
import com.daml.platform.store.entries.LedgerEntry
import com.daml.platform.store.serialization.{KeyHasher, ValueSerializer}
import com.daml.platform.store.{ActiveLedgerState, ActiveLedgerStateManager, Let, LetLookup}
import db.migration.translation.{ContractSerializer, TransactionSerializer}
import com.daml.platform.db.migration.translation.{ContractSerializer, TransactionSerializer}
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
import org.slf4j.LoggerFactory
@ -40,7 +40,7 @@ import scala.collection.immutable
* V2.0 adds corresponding new tables
* V2.1 fills the new tables
*/
class V2_1__Rebuild_Acs extends BaseJavaMigration {
private[migration] class V2_1__Rebuild_Acs extends BaseJavaMigration {
// Serializers used in SqlLedger/PostgresLedgerDao
private val keyHasher = KeyHasher

View File

@ -1,14 +1,14 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import com.daml.lf.data.Ref
import com.daml.lf.transaction.GlobalKey
import com.daml.platform.store.serialization.ValueSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
final class V32_1__Fix_key_hashes extends BaseJavaMigration {
private[migration] final class V32_1__Fix_key_hashes extends BaseJavaMigration {
private val SELECT_KEYS =
"select participant_events.contract_id, participant_events.template_id, create_key_value from participant_events inner join participant_contracts on participant_events.contract_id = participant_contracts.contract_id where create_key_value is not null"

View File

@ -3,7 +3,7 @@
// Note: package name must correspond exactly to the flyway 'locations' setting, which defaults to
// 'db.migration.postgres' for postgres migrations
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import java.sql.{Connection, ResultSet}
@ -14,7 +14,7 @@ import com.daml.lf.value.Value.ContractId
import com.daml.platform.store.serialization.{KeyHasher, ValueSerializer}
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V3__Recompute_Key_Hash extends BaseJavaMigration {
private[migration] class V3__Recompute_Key_Hash extends BaseJavaMigration {
// the number of contracts proceeded in a batch.
private val batchSize = 10 * 1000

View File

@ -3,7 +3,7 @@
// Note: package name must correspond exactly to the flyway 'locations' setting, which defaults to
// 'db.migration.postgres' for postgres migrations
package db.migration.postgres
package com.daml.platform.db.migration.postgres
import java.sql.{Connection, ResultSet}
@ -13,10 +13,10 @@ import com.daml.lf.transaction.{Transaction => Tx}
import com.daml.lf.transaction.Node.{NodeCreate, NodeExercises, NodeFetch, NodeLookupByKey}
import com.daml.lf.value.Value.ContractId
import com.daml.platform.store.Conversions._
import db.migration.translation.TransactionSerializer
import com.daml.platform.db.migration.translation.TransactionSerializer
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context}
class V4_1__Collect_Parties extends BaseJavaMigration {
private[migration] class V4_1__Collect_Parties extends BaseJavaMigration {
// the number of contracts proceeded in a batch.
private val batchSize = 10 * 1000

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v25_backfill_participant_events
package com.daml.platform.db.migration.postgres.v25_backfill_participant_events
import java.time.Instant

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v25_backfill_participant_events
package com.daml.platform.db.migration.postgres.v25_backfill_participant_events
import java.sql.Connection
import java.time.Instant
@ -11,7 +11,7 @@ import com.daml.ledger.{ApplicationId, CommandId, EventId, TransactionId, Workfl
import com.daml.lf.engine.Blinding
import com.daml.lf.transaction.BlindingInfo
object V25TransactionsWriter extends V25TransactionsWriter {
private[migration] object V25TransactionsWriter extends V25TransactionsWriter {
private def computeDisclosureForFlatTransaction(
transactionId: TransactionId,
@ -106,7 +106,7 @@ object V25TransactionsWriter extends V25TransactionsWriter {
}
trait V25TransactionsWriter {
private[migration] trait V25TransactionsWriter {
def apply(
applicationId: Option[ApplicationId],

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v25_backfill_participant_events
package com.daml.platform.db.migration.postgres.v25_backfill_participant_events
import anorm.{BatchSql, NamedParameter}
import com.daml.ledger.EventId

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
// Copied here to make it safe against future refactoring
// in production code
@ -11,19 +11,19 @@ package db.migration.postgres
package object v25_backfill_participant_events {
import com.daml.lf.value.{Value => lfval}
type ContractId = lfval.ContractId
private[migration] type ContractId = lfval.ContractId
import com.daml.lf.{transaction => lftx}
type NodeId = lftx.NodeId
type Transaction = lftx.Transaction.Transaction
type Create = lftx.Node.NodeCreate.WithTxValue[ContractId]
type Exercise = lftx.Node.NodeExercises.WithTxValue[NodeId, ContractId]
private[migration] type NodeId = lftx.NodeId
private[migration] type Transaction = lftx.Transaction.Transaction
private[migration] type Create = lftx.Node.NodeCreate.WithTxValue[ContractId]
private[migration] type Exercise = lftx.Node.NodeExercises.WithTxValue[NodeId, ContractId]
import com.daml.lf.{data => lfdata}
type Party = lfdata.Ref.Party
type Identifier = lfdata.Ref.Identifier
type LedgerString = lfdata.Ref.LedgerString
type WitnessRelation[A] = lfdata.Relation.Relation[A, Party]
type DisclosureRelation = WitnessRelation[NodeId]
val Relation = lfdata.Relation.Relation
private[migration] type Party = lfdata.Ref.Party
private[migration] type Identifier = lfdata.Ref.Identifier
private[migration] type LedgerString = lfdata.Ref.LedgerString
private[migration] type WitnessRelation[A] = lfdata.Relation.Relation[A, Party]
private[migration] type DisclosureRelation = WitnessRelation[NodeId]
private[migration] val Relation = lfdata.Relation.Relation
}

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v29_fix_participant_events
package com.daml.platform.db.migration.postgres.v29_fix_participant_events
import java.time.Instant

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v29_fix_participant_events
package com.daml.platform.db.migration.postgres.v29_fix_participant_events
import java.sql.Connection
import java.time.Instant
@ -11,7 +11,7 @@ import com.daml.ledger.{ApplicationId, CommandId, EventId, TransactionId, Workfl
import com.daml.lf.engine.Blinding
import com.daml.lf.transaction.BlindingInfo
object V29TransactionsWriter extends V29TransactionsWriter {
private[migration] object V29TransactionsWriter extends V29TransactionsWriter {
private def computeDisclosureForFlatTransaction(
transactionId: TransactionId,
@ -106,7 +106,7 @@ object V29TransactionsWriter extends V29TransactionsWriter {
}
trait V29TransactionsWriter {
private[migration] trait V29TransactionsWriter {
def apply(
applicationId: Option[ApplicationId],

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres.v29_fix_participant_events
package com.daml.platform.db.migration.postgres.v29_fix_participant_events
import anorm.{BatchSql, NamedParameter}
import com.daml.ledger.EventId

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.postgres
package com.daml.platform.db.migration.postgres
// Copied here to make it safe against future refactoring
// in production code
@ -11,19 +11,19 @@ package db.migration.postgres
package object v29_fix_participant_events {
import com.daml.lf.value.{Value => lfval}
type ContractId = lfval.ContractId
private[migration] type ContractId = lfval.ContractId
import com.daml.lf.{transaction => lftx}
type NodeId = lftx.NodeId
type Transaction = lftx.Transaction.Transaction
type Create = lftx.Node.NodeCreate.WithTxValue[ContractId]
type Exercise = lftx.Node.NodeExercises.WithTxValue[NodeId, ContractId]
private[migration] type NodeId = lftx.NodeId
private[migration] type Transaction = lftx.Transaction.Transaction
private[migration] type Create = lftx.Node.NodeCreate.WithTxValue[ContractId]
private[migration] type Exercise = lftx.Node.NodeExercises.WithTxValue[NodeId, ContractId]
import com.daml.lf.{data => lfdata}
type Party = lfdata.Ref.Party
type Identifier = lfdata.Ref.Identifier
type LedgerString = lfdata.Ref.LedgerString
type WitnessRelation[A] = lfdata.Relation.Relation[A, Party]
type DisclosureRelation = WitnessRelation[NodeId]
val Relation = lfdata.Relation.Relation
private[migration] type Party = lfdata.Ref.Party
private[migration] type Identifier = lfdata.Ref.Identifier
private[migration] type LedgerString = lfdata.Ref.LedgerString
private[migration] type WitnessRelation[A] = lfdata.Relation.Relation[A, Party]
private[migration] type DisclosureRelation = WitnessRelation[NodeId]
private[migration] val Relation = lfdata.Relation.Relation
}

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.translation
package com.daml.platform.db.migration.translation
import java.io.InputStream
@ -10,7 +10,7 @@ import com.daml.lf.transaction.{TransactionCoder, TransactionOuterClass}
import com.daml.lf.value.Value.{ContractId, ContractInst, VersionedValue}
import com.daml.lf.value.ValueCoder
trait ContractSerializer {
private[migration] trait ContractSerializer {
def serializeContractInstance(
coinst: ContractInst[VersionedValue[ContractId]]): Either[ValueCoder.EncodeError, Array[Byte]]
@ -21,7 +21,7 @@ trait ContractSerializer {
/**
* This is a preliminary serializer using protobuf as a payload type. Our goal on the long run is to use JSON as a payload.
*/
object ContractSerializer extends ContractSerializer {
private[migration] object ContractSerializer extends ContractSerializer {
override def serializeContractInstance(coinst: ContractInst[VersionedValue[ContractId]])
: Either[ValueCoder.EncodeError, Array[Byte]] =

View File

@ -1,7 +1,7 @@
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package db.migration.translation
package com.daml.platform.db.migration.translation
import java.io.InputStream
@ -11,7 +11,7 @@ import com.daml.lf.transaction.{CommittedTransaction, TransactionCoder, Transact
import com.daml.lf.value.ValueCoder
import com.daml.lf.value.ValueCoder.{DecodeError, EncodeError}
trait TransactionSerializer {
private[migration] trait TransactionSerializer {
def serializeTransaction(
trId: LedgerString,
@ -25,7 +25,7 @@ trait TransactionSerializer {
}
object TransactionSerializer extends TransactionSerializer {
private[migration] object TransactionSerializer extends TransactionSerializer {
override def serializeTransaction(
trId: LedgerString,

View File

@ -70,5 +70,10 @@ class FlywayMigrations(jdbcUrl: String)(implicit logCtx: LoggingContext) {
object FlywayMigrations {
def configurationBase(dbType: DbType): FluentConfiguration =
Flyway.configure().locations("classpath:db/migration/" + dbType.name)
Flyway
.configure()
.locations(
"classpath:com/daml/platform/db/migration/" + dbType.name,
"classpath:db/migration/" + dbType.name,
)
}