dimas-b commented on code in PR #2762:
URL: https://github.com/apache/polaris/pull/2762#discussion_r2411648483


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBootstrapUtils.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.polaris.core.persistence.bootstrap.BootstrapOptions;
+import org.apache.polaris.core.persistence.bootstrap.SchemaOptions;
+
+public class JdbcBootstrapUtils {
+
+  // Define a pattern to find 'v' followed by one or more digits (\d+)
+  private static final Pattern pattern = Pattern.compile("(v\\d+)");
+
+  private JdbcBootstrapUtils() {}
+
+  /**
+   * Determines the correct schema version to use for bootstrapping a realm.
+   *
+   * @param currentSchemaVersion The current version of the database schema.
+   * @param requiredSchemaVersion The requested schema version (-1 for 
auto-detection).
+   * @param hasAlreadyBootstrappedRealms Flag indicating if any realms already 
exist.
+   * @return The calculated bootstrap schema version.
+   * @throws IllegalStateException if the combination of parameters represents 
an invalid state.
+   */
+  public static int getRealmBootstrapSchemaVersion(
+      int currentSchemaVersion, int requiredSchemaVersion, boolean 
hasAlreadyBootstrappedRealms) {

Review Comment:
   It's more about overall confusion :sweat_smile: 
   
   We're trying to figure out what version of the DDL script to run when 
bootstrap is called.
   
   We check the version table and the existence of some other table and the 
bootstrap options.
   
   However, from my POV, the big question is whether to run the DDL at all.
   
   If tables exist and already contain realm `A` in schema `X`, then someone 
bootstraps realm `B` in schema `Y`, why would we (automatically) run DDL for 
`Y` and affect realm `A`?
   
   I'd think we should deduce the current schema version (`X`) and if `X != Y` 
error out (or require a new "upgrade" flag in `SchemaOptions`).



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