Skip to content

Commit

Permalink
Add user_project primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvv committed Oct 7, 2024
1 parent 8087749 commit 6270aa4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ services:
extends:
service: ztor-echo-schema-sql
command: ztor:run --args=create-schema
environment:
# other database
POSTGRES_URL: jdbc:postgresql://postgres:5432/gen

vallum-test:
extends:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ data class CompanyDataDocument(
zenmoProject = project.name ?: "Energieke Regio project ${project.energiekeRegioId}",
personName = "Contactpersoon",
project = project,
addresses =
listOf(
addresses = listOf(
Address(
id = UUID.randomUUID(),
street = getStringField("street"),
Expand All @@ -59,26 +58,15 @@ data class CompanyDataDocument(
GridConnection(
electricity =
Electricity(
hasConnection =
true,
annualElectricityDelivery_kWh =
getNumericField(
"annualElectricityDeliveryKwh"
)
.toInt(),
hasConnection = true,
annualElectricityDelivery_kWh = getNumericField("annualElectricityDeliveryKwh").toInt(),
annualElectricityFeedIn_kWh =
getNumericField(
"annualElectricityFeedinKwh"
)
.toInt(),
// ean =
// "123456789012345678",
quarterHourlyDelivery_kWh =
getElectricityDeliveryTimeSeries(),
getNumericField("annualElectricityFeedinKwh").toInt(),
// ean = "123456789012345678",
quarterHourlyDelivery_kWh = getElectricityDeliveryTimeSeries(),
quarterHourlyFeedIn_kWh = getElectricityFeedIn(),
quarterHourlyProduction_kWh = getElectricityProduction(),
grootverbruik =
CompanyGrootverbruik(
grootverbruik = CompanyGrootverbruik(
contractedConnectionDeliveryCapacity_kW =
getNumericField(
"contractedConnectionDeliveryCapacityKw"
Expand All @@ -92,10 +80,8 @@ data class CompanyDataDocument(
// physicalCapacityKw = 300,
),
),
supply =
Supply(
hasSupply =
true,
supply = Supply(
hasSupply = true,
pvInstalledKwp =
getNumericField(
"pvInstalledKwp"
Expand Down
6 changes: 6 additions & 0 deletions migrations/V28__user_project_pk.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE user_project
ADD CONSTRAINT pk_user_project
PRIMARY KEY (user_id, project_id);

ALTER TABLE survey_deeplink
ALTER COLUMN id SET DEFAULT gen_random_uuid();
6 changes: 2 additions & 4 deletions zorm/src/main/kotlin/com/zenmo/orm/deeplink/DeeplinkTable.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.zenmo.orm.deeplink

import com.zenmo.orm.companysurvey.table.CompanySurveyTable
import com.zenmo.orm.dbutil.ZenmoUUIDTable
import org.jetbrains.exposed.sql.ReferenceOption
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.kotlin.datetime.CurrentTimestamp
import org.jetbrains.exposed.sql.kotlin.datetime.timestamp

object DeeplinkTable: Table("survey_deeplink") {
val id = uuid("id").autoGenerate()
override val primaryKey = PrimaryKey(id)

object DeeplinkTable: ZenmoUUIDTable("survey_deeplink") {
val surveyId = uuid("survey_id").references(CompanySurveyTable.id, onDelete = ReferenceOption.CASCADE)
val created = timestamp("created").defaultExpression(CurrentTimestamp)
// val expires = timestamp("expires").nullable().default(null)
Expand Down
4 changes: 3 additions & 1 deletion zorm/src/main/kotlin/com/zenmo/orm/user/table/UserProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import org.jetbrains.exposed.sql.Table
object UserProjectTable: Table("user_project") {
val userId = reference("user_id", UserTable.id)
val projectId = reference("project_id", ProjectTable.id)
override val primaryKey = PrimaryKey(userId, projectId)

val scopes = enumArray("scopes", ProjectScope::class).default(emptyList())
}
}

0 comments on commit 6270aa4

Please sign in to comment.