-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pollux): add dal for the credential schema ATL-1342 (#298)
* feat(pollux): add schema-registry DAL * chore(pollux): fix migration * chore(pollux): fix formatting
- Loading branch information
1 parent
e990a92
commit f43320f
Showing
10 changed files
with
744 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
pollux/lib/sql-doobie/src/main/resources/sql/pollux/V3__schema_registry_tables.sql
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 @@ | ||
CREATE TABLE public.verifiable_credential_schema | ||
( | ||
id UUID PRIMARY KEY default gen_random_uuid(), | ||
name VARCHAR(128) NOT NULL, | ||
version VARCHAR(64) NOT NULL, | ||
tags VARCHAR(64) ARRAY NULL, | ||
description TEXT NULL, | ||
attributes VARCHAR(64) ARRAY NOT NULL, | ||
author VARCHAR(255) NOT NULL, | ||
authored TIMESTAMP WITH TIME ZONE NOT NULL, | ||
proof_id UUID NULL, | ||
UNIQUE (name, version, author) | ||
); | ||
|
||
CREATE INDEX name_index ON public.verifiable_credential_schema (name); | ||
CREATE INDEX version_index ON public.verifiable_credential_schema (version); | ||
CREATE INDEX tags_index ON public.verifiable_credential_schema (tags); | ||
CREATE INDEX attributes_index ON public.verifiable_credential_schema (attributes); | ||
CREATE INDEX author_index ON public.verifiable_credential_schema (author); | ||
CREATE INDEX authored_index ON public.verifiable_credential_schema (authored); | ||
|
||
CREATE TABLE public.proof | ||
( | ||
id UUID primary key default gen_random_uuid(), | ||
type VARCHAR(128) NOT NULL, | ||
created TIMESTAMP WITH TIME ZONE NOT NULL, | ||
verification_method VARCHAR(128) NOT NULL, | ||
proof_purpose VARCHAR(128) NOT NULL, | ||
proof_value TEXT NOT NULL, | ||
domain VARCHAR(255) NULL | ||
); | ||
|
||
|
||
|
||
CREATE INDEX type_index ON public.proof (type); | ||
CREATE INDEX verification_method_index ON public.proof (verification_method); | ||
CREATE INDEX proof_purpose_index ON public.proof (proof_purpose) | ||
|
||
|
||
|
104 changes: 104 additions & 0 deletions
104
...sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/VerifiableCredentialSchema.scala
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,104 @@ | ||
package io.iohk.atala.pollux.sql.model | ||
|
||
import io.getquill.doobie.DoobieContext | ||
import io.getquill.{Literal, SnakeCase, SqlMirrorContext} | ||
|
||
import java.time.{OffsetDateTime, ZonedDateTime} | ||
import java.util.UUID | ||
|
||
case class VerifiableCredentialSchema( | ||
id: UUID, | ||
name: String, | ||
version: String, | ||
tags: List[String], | ||
description: Option[String], | ||
attributes: List[String], | ||
author: String, | ||
authored: OffsetDateTime | ||
) { | ||
lazy val uniqueConstraintKey = author + name + version | ||
} | ||
|
||
object VerifiableCredentialSchema { | ||
object sql extends DoobieContext.Postgres(SnakeCase) { | ||
|
||
import io.getquill.* | ||
import io.getquill.idiom.* | ||
|
||
def insert(schema: VerifiableCredentialSchema) = run { | ||
quote { | ||
query[VerifiableCredentialSchema].insertValue(lift(schema)) | ||
} | ||
} | ||
|
||
def findBy(id: UUID) = run { | ||
quote { | ||
query[VerifiableCredentialSchema] | ||
.filter(schema => schema.id == lift(id)) | ||
.take(1) | ||
} | ||
} | ||
|
||
def update(schema: VerifiableCredentialSchema) = run { | ||
quote { | ||
query[VerifiableCredentialSchema] | ||
.filter(s => s.id == lift(schema.id)) | ||
.updateValue(lift(schema)) | ||
.returning(s => s) | ||
} | ||
} | ||
|
||
def delete(id: UUID) = run { | ||
quote { | ||
query[VerifiableCredentialSchema] | ||
.filter(schema => schema.id == lift(id)) | ||
.delete | ||
.returning(_.id) | ||
} | ||
} | ||
|
||
def deleteAll = run { | ||
quote { | ||
query[VerifiableCredentialSchema].delete | ||
} | ||
} | ||
|
||
def totalCount = run { | ||
quote { | ||
query[VerifiableCredentialSchema].size | ||
} | ||
} | ||
|
||
def lookup( | ||
authorOpt: Option[String] = None, | ||
nameOpt: Option[String] = None, | ||
versionOpt: Option[String] = None, | ||
attributeOpt: Option[String] = None, | ||
tagOpt: Option[String] = None, | ||
offsetOpt: Option[Int] = Some(0), | ||
limitOpt: Option[Int] = Some(100) | ||
) = { | ||
val quotedQuery = limitOpt | ||
.fold(quote(query[VerifiableCredentialSchema]))(limit => | ||
quote(query[VerifiableCredentialSchema].take(lift(limit))) | ||
) | ||
|
||
val dynamicQuery = quotedQuery.dynamic | ||
.filterOpt(authorOpt)((vcs, author) => quote(vcs.author.like(author))) | ||
.filterOpt(nameOpt)((vcs, name) => quote(vcs.name.like(name))) | ||
.filterOpt(versionOpt)((vcs, version) => quote(vcs.version.like(version))) | ||
.filter(vcs => | ||
attributeOpt | ||
.fold(quote(true))(attr => quote(vcs.attributes.contains(lift(attr)))) | ||
) | ||
.filter(vcs => | ||
tagOpt | ||
.fold(quote(true))(tag => quote(vcs.tags.contains(lift(tag)))) | ||
) | ||
.dropOpt(offsetOpt) | ||
.sortBy(vcs => vcs.id) | ||
|
||
dynamicQuery | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
pollux/lib/sql-doobie/src/test/resources/data/verifiableCredentialClaims.csv
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,20 @@ | ||
first_name | ||
second_name | ||
date_of_birth | ||
country_of_residence | ||
country_of_birth | ||
marriage_status | ||
sex | ||
degree | ||
alumni_of | ||
resident_of | ||
member_of | ||
owner_of | ||
grade | ||
score | ||
flight_destination | ||
flight_origin | ||
board_number | ||
booking_reference | ||
expired_date | ||
issuance_date |
40 changes: 40 additions & 0 deletions
40
pollux/lib/sql-doobie/src/test/resources/data/verifiableCredentialTypes.csv
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 @@ | ||
DrivingLicence | ||
Passport | ||
VaccinationCertificate | ||
FlightTicket | ||
MarriageCertificate | ||
BachelorDegree | ||
MasterDegree | ||
PhDDegree | ||
AWSCertifiedCloudPractitioner | ||
AWSCertifiedDeveloper | ||
AWSCertifiedSysOpsAdministrator–Associate(SOA-C02) | ||
AWSCertifiedSolutionsArchitect | ||
AWSCertifiedDevOpsEngineer | ||
AWSCertifiedSolutionsArchitect | ||
AWSCertifiedAdvancedNetworking | ||
AWSCertifiedSecurity–Specialty | ||
AWSCertifiedMachineLearning–Specialty | ||
AWSCertifiedDatabase | ||
AWSCertifiedDataAnalytics | ||
AWSCertifiedSAPonAWS | ||
GoogleCertifiedProfessionalCloudArchitect | ||
GoogleCertifiedProfessionalDataEngineer | ||
GoogleCertifiedProfessionalCloudDeveloper | ||
GoogleCertifiedGSuiteAdministrator | ||
GoogleCertifiedAssociateCloudEngineer | ||
GoogleCertifiedProfessionalCloudNetworkEngineer | ||
GoogleCertifiedProfessionalCloudSecurityEngineer | ||
GoogleCertifiedProfessionalCloudDevOpsEngineer | ||
GoogleCertifiedProfessionalCloudSolutionsArchitect | ||
GoogleCertifiedProfessionalCloudSecurityManager | ||
MicrosoftCertifiedSolutionsAssociate(MCSA):CloudPlatform | ||
MicrosoftCertifiedSolutionsExpert(MCSE):CloudPlatformandInfrastructure | ||
MicrosoftCertifiedSolutionsDeveloper(MCSD):AppBuilder | ||
MicrosoftCertifiedSolutionsAssociate(MCSA):WindowsServer2016 | ||
MicrosoftCertifiedSolutionsExpert(MCSE):Productivity | ||
MicrosoftCertifiedSolutionsExpert(MCSE):Mobility | ||
MicrosoftCertifiedSolutionsAssociate(MCSA):Office365 | ||
MicrosoftCertifiedSolutionsExpert(MCSE):DataManagement&Analytics | ||
MicrosoftCertifiedSolutionsExpert(MCSE):BusinessApplications | ||
MicrosoftCertifiedSolutionsAssociate(MCSA):LinuxonAzure |
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,20 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>[%level] %logger{15} - %message%n%rEx%xException{10}</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender"> | ||
<appender-ref ref="STDOUT"/> | ||
</appender> | ||
|
||
<logger name="io.getquill" level="OFF"/> | ||
<logger name="com.zaxxer.hikari" level="OFF"/> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="ASYNCSTDOUT"/> | ||
</root> | ||
|
||
</configuration> |
Oops, something went wrong.