This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] - New Versioning #284
Draft
Yawolf
wants to merge
2
commits into
master
Choose a base branch
from
new-versioning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
version = "2.5.2" | ||
style = defaultWithAlign | ||
maxColumn = 100 | ||
maxColumn = 120 | ||
|
||
continuationIndent.callSite = 2 | ||
|
||
|
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
2 changes: 1 addition & 1 deletion
2
src/main/resources/db/migration/data/V1__add_protocols_table.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CREATE TABLE protocols ( | ||
id CHARACTER VARYING(255) NOT NULL, | ||
version INTEGER NOT NULL, | ||
version VARCHAR(20) NOT NULL CHECK (version ~ '^(\d+\.)?(\d+\.)?(\*|\d+)$'), | ||
protocol BYTEA, | ||
PRIMARY KEY (id, version) | ||
); |
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ CREATE TYPE idl AS ENUM ('avro', 'protobuf', 'mu', 'openapi', 'scala'); | |
CREATE TABLE metaprotocols ( | ||
id CHARACTER VARYING(255) PRIMARY KEY, | ||
idl_name idl NOT NULL, | ||
version INTEGER NOT NULL | ||
version VARCHAR(20) NOT NULL CHECK (version ~ '^(\d+\.)?(\d+\.)?(\*|\d+)$') | ||
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. Same as above |
||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ import eu.timepit.refined.boolean.{And, AnyOf} | |
import eu.timepit.refined.char.LetterOrDigit | ||
import eu.timepit.refined.collection.{Forall, MaxSize} | ||
import eu.timepit.refined.generic.Equal | ||
import eu.timepit.refined.numeric.Positive | ||
import higherkindness.compendium.models.{ProtocolIdError, ProtocolVersionError} | ||
import eu.timepit.refined.string.MatchesRegex | ||
import higherkindness.compendium.models._ | ||
import shapeless.{::, HNil} | ||
|
||
object refinements { | ||
|
@@ -37,19 +37,20 @@ object refinements { | |
type ProtocolIdConstraints = And[MaxProtocolIdSize, ValidProtocolIdChars] | ||
|
||
type ProtocolId = String Refined ProtocolIdConstraints | ||
|
||
object ProtocolId extends RefinedTypeOps[ProtocolId, String] { | ||
def parseOrRaise[F[_]: Sync](id: String): F[ProtocolId] = | ||
F.fromEither(ProtocolId.from(id).leftMap(ProtocolIdError)) | ||
} | ||
|
||
type ProtocolVersion = Int Refined Positive | ||
/** An String that matches with format xx.yy.zz, xx.yy, xx */ | ||
type ProtocolVersionRefined = | ||
String Refined MatchesRegex[W.`"""^(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$"""`.T] | ||
object ProtocolVersionRefined extends RefinedTypeOps[ProtocolVersionRefined, String] { | ||
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. Maybe we don't need this anymore... I have to give it a deeper look |
||
|
||
object ProtocolVersion extends RefinedTypeOps[ProtocolVersion, Int] { | ||
def parseOrRaise[F[_]: Sync](version: String): F[ProtocolVersion] = | ||
for { | ||
number <- F.delay(version.toInt) | ||
protoVersion <- F.fromEither(ProtocolVersion.from(number).leftMap(ProtocolVersionError)) | ||
} yield protoVersion | ||
versionRefined <- F.fromEither(ProtocolVersionRefined.from(version).leftMap(ProtocolVersionError)) | ||
protocolVersion <- F.fromEither(ProtocolVersion.fromString(versionRefined.value)) | ||
} yield protocolVersion | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,10 @@ | |
package higherkindness.compendium.metadata.pg | ||
|
||
import doobie.implicits._ | ||
import doobie.{Query0, Update0} | ||
import doobie._ | ||
import higherkindness.compendium.core.doobie.implicits._ | ||
import higherkindness.compendium.core.refinements.ProtocolId | ||
import higherkindness.compendium.models.ProtocolMetadata | ||
import higherkindness.compendium.models._ | ||
|
||
object Queries { | ||
|
||
|
@@ -29,11 +29,11 @@ object Queries { | |
SELECT exists (SELECT true FROM metaprotocols WHERE id=$id) | ||
""".query[Boolean] | ||
|
||
def store(id: ProtocolId, idl_name: String): Update0 = | ||
def store(id: ProtocolId, protocol_version: ProtocolVersion, idl_name: String): Update0 = | ||
sql""" | ||
INSERT INTO metaprotocols (id, idl_name, version) | ||
VALUES ($id, $idl_name::idl, 1) | ||
ON CONFLICT (id) DO UPDATE SET version = metaprotocols.version + 1 | ||
VALUES ($id, $idl_name::idl, $protocol_version) | ||
ON CONFLICT (id) DO UPDATE SET version = ${protocol_version.incRevision} | ||
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. The Revision is updated by default, but this can be changed |
||
RETURNING version | ||
""".update | ||
|
||
|
@@ -44,4 +44,9 @@ object Queries { | |
|
||
def checkConn: Query0[Boolean] = | ||
sql"SELECT exists (SELECT 1)".query[Boolean] | ||
|
||
val checkVersion: Query[ProtocolId, ProtocolVersion] = | ||
Query( | ||
"SELECT version from metaprotocols WHERE id = ?" | ||
) | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I did this here because of the tests, but I guess the correct way would be to create a migration?