From 51692ded040150c0bb4713cb86d088ae95094f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bo=CC=88hm?= Date: Thu, 11 Apr 2019 10:47:22 +0200 Subject: [PATCH 1/2] implement _datamodel endpoint for project --- .../jdbc/persistence/JdbcProjectPersistence.scala | 7 ++++--- .../prisma/deploy/connector/mongo/impl/DbMapper.scala | 3 ++- .../scala/com/prisma/image/SangriaHandlerImpl.scala | 7 ++++++- .../deploy/persistence/ProjectPersistenceSpec.scala | 10 ++++++---- .../main/scala/com/prisma/shared/models/Project.scala | 3 ++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/server/connectors/deploy-connector-jdbc/src/main/scala/com/prisma/deploy/connector/jdbc/persistence/JdbcProjectPersistence.scala b/server/connectors/deploy-connector-jdbc/src/main/scala/com/prisma/deploy/connector/jdbc/persistence/JdbcProjectPersistence.scala index dfc8ccaaf9..9eff02462c 100644 --- a/server/connectors/deploy-connector-jdbc/src/main/scala/com/prisma/deploy/connector/jdbc/persistence/JdbcProjectPersistence.scala +++ b/server/connectors/deploy-connector-jdbc/src/main/scala/com/prisma/deploy/connector/jdbc/persistence/JdbcProjectPersistence.scala @@ -35,7 +35,7 @@ case class JdbcProjectPersistence(slickDatabase: SlickDatabase, dbConfig: Databa override def load(id: String): Future[Option[Project]] = { val query = sql - .select(pt.id, pt.secrets, pt.allowQueries, pt.allowMutations, mt.schema, mt.functions, mt.revision) + .select(pt.id, pt.secrets, pt.allowQueries, pt.allowMutations, mt.schema, mt.functions, mt.revision, mt.dataModel) .from(pt.t) .join(mt.t) .on(mt.projectId.equal(pt.id)) @@ -74,7 +74,7 @@ case class JdbcProjectPersistence(slickDatabase: SlickDatabase, dbConfig: Databa .from(mt.t.as("outer")) val query = sql - .select(pt.id, pt.secrets, pt.allowQueries, pt.allowMutations, mt.schema, mt.functions, mt.revision) + .select(pt.id, pt.secrets, pt.allowQueries, pt.allowMutations, mt.schema, mt.functions, mt.revision, mt.dataModel) .from(pt.t) .join(revisionQuery.asTable("jt")) .on(field(name("jt", "projectId")).equal(pt.id)) @@ -164,7 +164,8 @@ case class JdbcProjectPersistence(slickDatabase: SlickDatabase, dbConfig: Databa allowQueries = rs.getBoolean(pt.allowQueries.getName), allowMutations = rs.getBoolean(pt.allowMutations.getName), functions = functions, - manifestation = projectManifestation + manifestation = projectManifestation, + rawDataModel = rs.getString(mt.dataModel.getName) ) } } diff --git a/server/connectors/deploy-connector-mongo/src/main/scala/com/prisma/deploy/connector/mongo/impl/DbMapper.scala b/server/connectors/deploy-connector-mongo/src/main/scala/com/prisma/deploy/connector/mongo/impl/DbMapper.scala index 9a522af75a..3568b2e2a4 100644 --- a/server/connectors/deploy-connector-mongo/src/main/scala/com/prisma/deploy/connector/mongo/impl/DbMapper.scala +++ b/server/connectors/deploy-connector-mongo/src/main/scala/com/prisma/deploy/connector/mongo/impl/DbMapper.scala @@ -53,7 +53,8 @@ object DbMapper extends JsonBsonConversion with MongoExtensions { revision = migration.revision, schema = schemaWithAddedBackRelations, functions = migration.functions.toList, - manifestation = manifestation + manifestation = manifestation, + rawDataModel = migration.rawDataModel ) } diff --git a/server/images/prisma-image-shared/src/main/scala/com/prisma/image/SangriaHandlerImpl.scala b/server/images/prisma-image-shared/src/main/scala/com/prisma/image/SangriaHandlerImpl.scala index d1f2141ed2..997e3c35d7 100644 --- a/server/images/prisma-image-shared/src/main/scala/com/prisma/image/SangriaHandlerImpl.scala +++ b/server/images/prisma-image-shared/src/main/scala/com/prisma/image/SangriaHandlerImpl.scala @@ -74,6 +74,11 @@ case class SangriaHandlerImpl(managementApiEnabled: Boolean)( sys.error(s"The connector is missing the import / export capability.") } } + case Some("_datamodel") => + verifyAuth(projectIdAsString, rawRequest) { project => + val response = Response(Json.toJson(project.rawDataModel)) + Future.successful(response) + } case _ => requestThrottler.throttleCallIfNeeded(projectIdAsString, isManagementApiRequest = isManagementApiRequest(rawRequest)) { @@ -175,7 +180,7 @@ case class SangriaHandlerImpl(managementApiEnabled: Boolean)( } private def splitReservedSegment(elements: List[String]): (List[String], Option[String]) = { - val reservedSegments = Set("private", "import", "export") + val reservedSegments = Set("private", "import", "export", "_datamodel") if (elements.nonEmpty && reservedSegments.contains(elements.last)) { (elements.dropRight(1), elements.lastOption) } else { diff --git a/server/servers/deploy/src/test/scala/com/prisma/deploy/persistence/ProjectPersistenceSpec.scala b/server/servers/deploy/src/test/scala/com/prisma/deploy/persistence/ProjectPersistenceSpec.scala index 99ec204a9e..22cf045ba3 100644 --- a/server/servers/deploy/src/test/scala/com/prisma/deploy/persistence/ProjectPersistenceSpec.scala +++ b/server/servers/deploy/src/test/scala/com/prisma/deploy/persistence/ProjectPersistenceSpec.scala @@ -27,7 +27,9 @@ class ProjectPersistenceSpec extends FlatSpec with Matchers with DeploySpecBase } // Load the applied revision, which is 2 (2 steps are done in setupProject) - loadProject.get.revision shouldEqual 2 + val project1 = loadProject.get + project1.revision shouldEqual 2 + project1.rawDataModel should equal(basicTypesGql) // After another migration is completed, the revision is bumped to the revision of the latest migration migrationPersistence.updateMigrationStatus(MigrationId(project.id, 3), MigrationStatus.Success).await @@ -48,12 +50,13 @@ class ProjectPersistenceSpec extends FlatSpec with Matchers with DeploySpecBase setupProject(basicTypesGql, stage = "stage1") setupProject(basicTypesGql, stage = "stage2") - projectPersistence.loadAll().await should have(size(2)) + val projects = projectPersistence.loadAll().await + projects should have(size(2)) + projects.foreach(p => p.rawDataModel should equal(basicTypesGql)) } ".update()" should "update a project" in { val (project, _) = setupProject(basicTypesGql) - println(project.id) val updatedProject = project.copy(secrets = Vector("Some", "secrets")) projectPersistence.update(updatedProject).await() @@ -67,7 +70,6 @@ class ProjectPersistenceSpec extends FlatSpec with Matchers with DeploySpecBase ".delete()" should "delete a project" in { val (project, _) = setupProject(basicTypesGql) - println(project.id) projectPersistence.delete(project.id).await() projectPersistence.load(project.id).await should be(None) diff --git a/server/shared-models/src/main/scala/com/prisma/shared/models/Project.scala b/server/shared-models/src/main/scala/com/prisma/shared/models/Project.scala index ccdf08171f..224b7621e9 100644 --- a/server/shared-models/src/main/scala/com/prisma/shared/models/Project.scala +++ b/server/shared-models/src/main/scala/com/prisma/shared/models/Project.scala @@ -10,7 +10,8 @@ case class Project( allowQueries: Boolean = true, allowMutations: Boolean = true, functions: List[Function] = List.empty, - manifestation: ProjectManifestation = ProjectManifestation.empty + manifestation: ProjectManifestation = ProjectManifestation.empty, + rawDataModel: String = "" ) { def models = schema.models def relations = schema.relations From 8f3dfb653096175d0b7c0b54fe6d6cf330389342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bo=CC=88hm?= Date: Thu, 11 Apr 2019 11:41:40 +0200 Subject: [PATCH 2/2] deactivate build steps for native image --- .../.buildkite/build-cli/src/pipeline_renderer.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/.buildkite/build-cli/src/pipeline_renderer.rb b/server/.buildkite/build-cli/src/pipeline_renderer.rb index 3342368805..d9ef7b6ca0 100644 --- a/server/.buildkite/build-cli/src/pipeline_renderer.rb +++ b/server/.buildkite/build-cli/src/pipeline_renderer.rb @@ -153,12 +153,13 @@ def release_artifacts_steps end def build_steps_for(version) - ['debian', 'lambda'].map do |target| - PipelineStep.new - .label(":rust: Native image [#{target}] [#{version}]") - .command("./server/.buildkite/pipeline.sh native-image #{target} #{version}") - .queue("native-linux") - end + # ['debian', 'lambda'].map do |target| + # PipelineStep.new + # .label(":rust: Native image [#{target}] [#{version}]") + # .command("./server/.buildkite/pipeline.sh native-image #{target} #{version}") + # .queue("native-linux") + # end + [] end def calculate_next_unstable_docker_tag()