adutra commented on code in PR #4945:
URL: https://github.com/apache/polaris/pull/4945#discussion_r3623217196


##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperationsSchemaTest.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.polaris.persistence.relational.jdbc;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import javax.sql.DataSource;
+import org.h2.jdbcx.JdbcConnectionPool;
+import org.junit.jupiter.api.Test;
+
+/**
+ * End-to-end tests against a real H2 database showing that the persistence 
code is agnostic of the
+ * database schema: the schema is created and selected entirely through the 
datasource (here via
+ * H2's {@code INIT=} URL setting, the equivalent of the PostgreSQL driver's 
{@code currentSchema}
+ * connection property plus a DBA-created schema), and the unqualified SQL 
generated by the
+ * persistence layer resolves against it.
+ */
+class DatasourceOperationsSchemaTest {
+
+  private static DataSource createDataSource(String schemaName) {
+    String url = "jdbc:h2:mem:schema_test_" + UUID.randomUUID() + 
";DB_CLOSE_DELAY=-1";
+    if (schemaName != null) {
+      url += ";INIT=CREATE SCHEMA IF NOT EXISTS " + schemaName + "\\;SET 
SCHEMA " + schemaName;
+    }
+    return JdbcConnectionPool.create(url, "sa", "");
+  }
+
+  private static InputStream openSchemaScript() {
+    return 
DatasourceOperations.class.getClassLoader().getResourceAsStream("h2/schema-v5.sql");
+  }
+
+  /** Schemas holding an ENTITIES table, as reported by the database catalog. 
*/
+  private static List<String> schemasContainingEntitiesTable(DataSource 
dataSource)
+      throws SQLException {
+    List<String> schemas = new ArrayList<>();
+    try (Connection connection = dataSource.getConnection();
+        PreparedStatement statement =
+            connection.prepareStatement(
+                "SELECT table_schema FROM information_schema.tables WHERE 
table_name = 'ENTITIES'")) {

Review Comment:
   Maybe add `LIMIT 1` and return just the first row?



##########
site/content/guides/assets/postgres/docker-compose-postgres.yml:
##########
@@ -34,6 +34,10 @@ services:
       - type: bind
         source: ${ASSETS_PATH}/postgres/postgresql.conf
         target: /etc/postgresql/postgresql.conf
+      # Create the Polaris schema on first init: Polaris does not create it 
itself
+      - type: bind
+        source: ${ASSETS_PATH}/postgres/create-polaris-schema.sql
+        target: /docker-entrypoint-initdb.d/create-polaris-schema.sql

Review Comment:
   Very elegant 👍 



##########
helm/polaris/ci/fixtures/postgres.yaml:
##########
@@ -58,6 +58,23 @@ spec:
             periodSeconds: 5
             timeoutSeconds: 2
             failureThreshold: 15
+          volumeMounts:
+            # Create the Polaris schema on first init: Polaris does not create 
it itself.
+            - name: init-schema
+              mountPath: /docker-entrypoint-initdb.d

Review Comment:
   I love the `docker-entrypoint-initdb.d` approach 😄 



-- 
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