-
Notifications
You must be signed in to change notification settings - Fork 51
Switch to relying on package names instead of module names #1976
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
Changes from all commits
ff086b9
ea2f40a
ee72588
cae3fad
4199050
0c01122
096ea57
24b712a
3b845ce
50077da
15d666a
a76111d
59c5890
3184d5a
5910a9f
1680a64
dc7e00d
5bfdbca
cb9983f
16df3a3
5ca46b9
553b6c9
583b0cb
df27b53
684be68
498948c
b82028d
d201c0f
6f8f951
74fea0e
2a04dac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,24 +26,33 @@ import scalaz.{@@, Tag} | |
| import slick.jdbc.canton.ActionBasedSQLInterpolation.Implicits.actionBasedSQLInterpolationCanton | ||
| import slick.jdbc.canton.SQLActionBuilder | ||
| import slick.jdbc.{GetResult, PositionedResult, SetParameter} | ||
| import slick.dbio.Effect | ||
| import slick.sql.SqlStreamingAction | ||
|
|
||
| trait AcsQueries extends AcsJdbcTypes { | ||
|
|
||
| /** @param tableName Must be SQL-safe, as it needs to be interpolated unsafely. | ||
| * This is fine, as all calls to this method should use static string constants. | ||
| */ | ||
| protected def selectFromAcsTable( | ||
| protected def selectFromAcsTable[C, TCid <: ContractId[_], T]( | ||
| tableName: String, | ||
| storeId: AcsStoreId, | ||
| migrationId: Long, | ||
| where: SQLActionBuilder, | ||
| companion: C, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should've been the case all along, instead of having
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, thanks for pulling through that simplification! |
||
| where: SQLActionBuilder = sql"true", | ||
| orderLimit: SQLActionBuilder = sql"", | ||
| ) = | ||
| )(implicit companionClass: ContractCompanion[C, TCid, T]) = { | ||
| val packageQualifiedName = companionClass.packageQualifiedName(companion) | ||
| (sql""" | ||
| select #${SelectFromAcsTableResult.sqlColumnsCommaSeparated()} | ||
| from #$tableName acs | ||
| where acs.store_id = $storeId and acs.migration_id = $migrationId and """ ++ where ++ sql""" | ||
| where acs.store_id = $storeId | ||
| and acs.migration_id = $migrationId | ||
| and acs.package_name = ${packageQualifiedName.packageName} | ||
| and acs.template_id_qualified_name = ${packageQualifiedName.qualifiedName} | ||
| and """ ++ where ++ sql""" | ||
| """ ++ orderLimit).toActionBuilder.as[AcsQueries.SelectFromAcsTableResult] | ||
| } | ||
|
|
||
| implicit val GetResultSelectFromAcsTable: GetResult[AcsQueries.SelectFromAcsTableResult] = | ||
| GetResult { prs => | ||
|
|
@@ -55,7 +64,7 @@ trait AcsQueries extends AcsJdbcTypes { | |
| <<[Long], | ||
| <<[ContractId[Any]], | ||
| <<[String], | ||
| <<[QualifiedName], | ||
| <<[PackageQualifiedName], | ||
| <<[Json], | ||
| <<[Array[Byte]], | ||
| <<[Timestamp], | ||
|
|
@@ -65,18 +74,27 @@ trait AcsQueries extends AcsJdbcTypes { | |
| } | ||
|
|
||
| /** Similar to [[selectFromAcsTable]], but also returns the contract state (i.e., the domain to which a contract is currently assigned) */ | ||
| protected def selectFromAcsTableWithState( | ||
| protected def selectFromAcsTableWithState[C, TCid <: ContractId[_], T]( | ||
| tableName: String, | ||
| storeId: AcsStoreId, | ||
| migrationId: Long, | ||
| where: SQLActionBuilder, | ||
| companion: C, | ||
| additionalWhere: SQLActionBuilder = sql"", | ||
| orderLimit: SQLActionBuilder = sql"", | ||
| ) = | ||
| )(implicit companionClass: ContractCompanion[C, TCid, T]): SqlStreamingAction[Vector[ | ||
| SelectFromAcsTableWithStateResult | ||
| ], SelectFromAcsTableWithStateResult, Effect.Read] = { | ||
| val packageQualifiedName = companionClass.packageQualifiedName(companion) | ||
| (sql""" | ||
| select #${SelectFromAcsTableWithStateResult.sqlColumnsCommaSeparated()} | ||
| from #$tableName acs | ||
| where acs.store_id = $storeId and acs.migration_id = $migrationId and """ ++ where ++ sql""" | ||
| where acs.store_id = $storeId | ||
| and acs.migration_id = $migrationId | ||
| and acs.package_name = ${packageQualifiedName.packageName} | ||
| and acs.template_id_qualified_name = ${packageQualifiedName.qualifiedName} | ||
| """ ++ additionalWhere ++ sql""" | ||
| """ ++ orderLimit).toActionBuilder.as[AcsQueries.SelectFromAcsTableWithStateResult] | ||
| } | ||
|
|
||
| implicit val GetResultSelectFromContractStateResult | ||
| : GetResult[AcsQueries.SelectFromContractStateResult] = | ||
|
|
@@ -104,13 +122,15 @@ trait AcsQueries extends AcsJdbcTypes { | |
| * This guarantees that the fetched contracts exist in the given offset, | ||
| * whereas two separate queries (one to fetch the contract and one to fetch the offset) don't guarantee that. | ||
| */ | ||
| protected def selectFromAcsTableWithOffset( | ||
| protected def selectFromAcsTableWithOffset[C, TCid <: ContractId[_], T]( | ||
| tableName: String, | ||
| storeId: AcsStoreId, | ||
| migrationId: Long, | ||
| companion: C, | ||
| where: SQLActionBuilder, | ||
| orderLimit: SQLActionBuilder = sql"", | ||
| ) = | ||
| )(implicit companionClass: ContractCompanion[C, TCid, T]) = { | ||
| val packageQualifiedName = companionClass.packageQualifiedName(companion) | ||
| (sql""" | ||
| select | ||
| acs.store_id, | ||
|
|
@@ -120,6 +140,7 @@ trait AcsQueries extends AcsJdbcTypes { | |
| contract_id, | ||
| template_id_package_id, | ||
| template_id_qualified_name, | ||
| package_name, | ||
| create_arguments, | ||
| created_event_blob, | ||
| created_at, | ||
|
|
@@ -130,10 +151,13 @@ trait AcsQueries extends AcsJdbcTypes { | |
| left join #$tableName acs | ||
| on o.store_id = acs.store_id | ||
| and o.migration_id = acs.migration_id | ||
| and acs.package_name = ${packageQualifiedName.packageName} | ||
| and acs.template_id_qualified_name = ${packageQualifiedName.qualifiedName} | ||
| and """ ++ where ++ sql""" | ||
| where sd.id = $storeId and o.migration_id = $migrationId | ||
| """ ++ orderLimit).toActionBuilder | ||
| .as[AcsQueries.SelectFromAcsTableResultWithOffset] | ||
| } | ||
|
|
||
| implicit val GetResultSelectFromAcsTableResultWithOffset | ||
| : GetResult[AcsQueries.SelectFromAcsTableResultWithOffset] = { (pp: PositionedResult) => | ||
|
|
@@ -161,13 +185,15 @@ trait AcsQueries extends AcsJdbcTypes { | |
|
|
||
| /** Same as [[selectFromAcsTableWithOffset]], but also includes the contract state. | ||
| */ | ||
| protected def selectFromAcsTableWithStateAndOffset( | ||
| protected def selectFromAcsTableWithStateAndOffset[C, TCid <: ContractId[_], T]( | ||
| tableName: String, | ||
| storeId: AcsStoreId, | ||
| migrationId: Long, | ||
| companion: C, | ||
| where: SQLActionBuilder = sql"true", | ||
| orderLimit: SQLActionBuilder = sql"", | ||
| ) = | ||
| )(implicit companionClass: ContractCompanion[C, TCid, T]) = { | ||
| val packageQualifiedName = companionClass.packageQualifiedName(companion) | ||
| (sql""" | ||
| select | ||
| acs.store_id, | ||
|
|
@@ -177,6 +203,7 @@ trait AcsQueries extends AcsJdbcTypes { | |
| acs.contract_id, | ||
| acs.template_id_package_id, | ||
| acs.template_id_qualified_name, | ||
| acs.package_name, | ||
| acs.create_arguments, | ||
| acs.created_event_blob, | ||
| acs.created_at, | ||
|
|
@@ -194,10 +221,13 @@ trait AcsQueries extends AcsJdbcTypes { | |
| left join #$tableName acs | ||
| on o.store_id = acs.store_id | ||
| and o.migration_id = acs.migration_id | ||
| and acs.package_name = ${packageQualifiedName.packageName} | ||
| and acs.template_id_qualified_name = ${packageQualifiedName.qualifiedName} | ||
| and """ ++ where ++ sql""" | ||
| where sd.id = $storeId and o.migration_id = $migrationId | ||
| """ ++ orderLimit).toActionBuilder | ||
| .as[AcsQueries.SelectFromAcsTableResultWithStateAndOffset] | ||
| } | ||
|
|
||
| implicit val GetResultSelectFromAcsTableResultWithStateOffset | ||
| : GetResult[AcsQueries.SelectFromAcsTableResultWithStateAndOffset] = { | ||
|
|
@@ -311,7 +341,7 @@ object AcsQueries { | |
| eventNumber: Long, | ||
| contractId: ContractId[Any], | ||
| templateIdPackageId: String, | ||
| templateIdQualifiedName: QualifiedName, | ||
| packageQualifiedName: PackageQualifiedName, | ||
| createArguments: Json, | ||
| createdEventBlob: Array[Byte], | ||
| createdAt: Timestamp, | ||
|
|
@@ -321,12 +351,22 @@ object AcsQueries { | |
| companionClass: ContractCompanion[C, TCId, T], | ||
| decoder: TemplateJsonDecoder, | ||
| ): Contract[TCId, T] = { | ||
| // safety check: if the PackageQualifiedNames don't match, | ||
| // it means that we would be returning a contract of a different template | ||
| // note that the packageId not matching is expected due to upgrades, but the name will be stable | ||
| val expectedPackageQualifiedName = companionClass.packageQualifiedName(companion) | ||
| if (expectedPackageQualifiedName != packageQualifiedName) { | ||
| throw new IllegalStateException( | ||
| s"Contract $contractId has a different package qualified name than expected. Expected: $expectedPackageQualifiedName - Got: $packageQualifiedName" | ||
| ) | ||
| } | ||
|
|
||
| companionClass | ||
| .fromJson(companion)( | ||
| new Identifier( | ||
| templateIdPackageId, | ||
| templateIdQualifiedName.moduleName, | ||
| templateIdQualifiedName.entityName, | ||
| packageQualifiedName.qualifiedName.moduleName, | ||
| packageQualifiedName.qualifiedName.entityName, | ||
| ), | ||
| contractId.contractId, | ||
| createArguments, | ||
|
|
@@ -351,6 +391,7 @@ object AcsQueries { | |
| ${qualifier}contract_id, | ||
| ${qualifier}template_id_package_id, | ||
| ${qualifier}template_id_qualified_name, | ||
| ${qualifier}package_name, | ||
| ${qualifier}create_arguments, | ||
| ${qualifier}created_event_blob, | ||
| ${qualifier}created_at, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused except in a test (also deleted)