Copilot commented on code in PR #7386:
URL: https://github.com/apache/texera/pull/7386#discussion_r3744127491


##########
common/dao/src/test/scala/org/apache/texera/dao/UserWarehouseSpec.scala:
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.dao
+
+import org.apache.texera.dao.jooq.generated.Tables.{USER, USER_WAREHOUSE}
+import org.jooq.exception.DataAccessException
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+/**
+  * Spec for the `user_warehouse` table (#6931). Schema only — nothing reads 
or writes the
+  * table in production yet — so this pins the DDL's structural properties 
(columns, the
+  * per-user name uniqueness, and the ownership cascade) against the generated 
jOOQ classes.
+  */
+class UserWarehouseSpec extends AnyFlatSpec with Matchers with 
BeforeAndAfterAll with MockTexeraDB {
+
+  override protected def beforeAll(): Unit = {
+    super.beforeAll()
+    initializeDBAndReplaceDSLContext()
+  }
+
+  override protected def afterAll(): Unit =
+    try closeConnectionPool()
+    finally super.afterAll()
+
+  private def insertUser(name: String): Integer =
+    getDSLContext
+      .insertInto(USER, USER.NAME, USER.PASSWORD)
+      .values(name, "password")
+      .returning(USER.UID)
+      .fetchOne()
+      .getUid
+
+  private def insertWarehouse(uid: Integer, name: String, warehouseName: 
String): Integer =
+    getDSLContext
+      .insertInto(
+        USER_WAREHOUSE,
+        USER_WAREHOUSE.UID,
+        USER_WAREHOUSE.NAME,
+        USER_WAREHOUSE.WAREHOUSE_NAME,
+        USER_WAREHOUSE.FLAVOR
+      )
+      .values(uid, name, warehouseName, "local")
+      .returning(USER_WAREHOUSE.WHID)
+      .fetchOne()
+      .getWhid
+
+  "user_warehouse" should "store a registered warehouse and return it by 
owner" in {
+    val uid = insertUser("warehouse-owner")
+    insertWarehouse(uid, "mybucket", s"user-$uid-mybucket")
+
+    val row = getDSLContext
+      .selectFrom(USER_WAREHOUSE)
+      .where(USER_WAREHOUSE.UID.eq(uid))
+      .fetchOne()
+    row.getName shouldBe "mybucket"
+    row.getWarehouseName shouldBe s"user-$uid-mybucket"
+    row.getFlavor shouldBe "local"
+    row.getCreatedAt should not be null
+  }
+
+  it should "enforce one warehouse name per user" in {
+    val uid = insertUser("duplicate-name-owner")
+    insertWarehouse(uid, "dup", s"user-$uid-dup")
+
+    a[DataAccessException] should be thrownBy
+      insertWarehouse(uid, "dup", s"user-$uid-dup-2")
+  }

Review Comment:
   This spec verifies the per-user uniqueness constraint, but it doesn’t pin 
the global `UNIQUE` constraint on `warehouse_name` from the DDL. Also, the 
current test name is ambiguous because `warehouse_name` is a separate column; 
renaming it reduces confusion about which constraint is being asserted.



##########
sql/updates/32.sql:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+\c texera_db
+
+SET search_path TO texera_db;
+
+BEGIN;
+
+-- Per-user warehouse registrations (#6870): one row per warehouse a user 
registered.
+-- Base columns only; the assume-role (BYO-S3) columns come in a later change.
+CREATE TABLE IF NOT EXISTS user_warehouse
+(
+    whid                    SERIAL PRIMARY KEY,
+    uid                     INT          NOT NULL,
+    name                    VARCHAR(128) NOT NULL,
+    warehouse_name          VARCHAR(255) NOT NULL UNIQUE,
+    lakekeeper_warehouse_id UUID,
+    flavor                  VARCHAR(32)  NOT NULL,
+    s3_bucket               VARCHAR(255),
+    s3_endpoint             VARCHAR(255),

Review Comment:
   `flavor` is stored as an unconstrained string, which allows invalid values 
to be inserted (e.g., typos) and makes future code more brittle. Since this 
column represents a small finite set of flavors (e.g., local vs cloud), 
consider enforcing it at the DB level (Postgres enum type or a CHECK 
constraint) so jOOQ and the database agree on the allowed values.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to