galovics commented on code in PR #2344:
URL: https://github.com/apache/fineract/pull/2344#discussion_r886410540


##########
fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0004_readonly_database_connection.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog";
+                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                   
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd";>
+    <changeSet author="fineract" 
id="add-readonly-database-connection-properties" context="tenant_store_db">
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_name" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server_port" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_username" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_password" type="VARCHAR(100)"/>
+        </addColumn>
+    </changeSet>
+    <changeSet author="fineract" 
id="set-readonly-database-connection-properties" context="tenant_store_db">
+        <sql>
+            UPDATE tenant_server_connections SET 
readonly_schema_server=schema_server, readonly_schema_name=schema_name, 
readonly_schema_server_port=schema_server_port, 
readonly_schema_username=schema_username, 
readonly_schema_password=schema_password

Review Comment:
   Well, I'm not sure if we want to "lie" here. I'd say the read only columns 
could stay null and when the app starts up in a read-only mode, it smartly 
recognizes that  if not all of the readonly parameters are filled, it simply 
falls back to the normal parameters.
   Thoughts?



##########
fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0004_readonly_database_connection.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog";
+                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                   
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd";>
+    <changeSet author="fineract" 
id="add-readonly-database-connection-properties" context="tenant_store_db">
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_name" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server_port" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_username" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_password" type="VARCHAR(100)"/>
+        </addColumn>
+    </changeSet>
+    <changeSet author="fineract" 
id="set-readonly-database-connection-properties" context="tenant_store_db">
+        <sql>
+            UPDATE tenant_server_connections SET 
readonly_schema_server=schema_server, readonly_schema_name=schema_name, 
readonly_schema_server_port=schema_server_port, 
readonly_schema_username=schema_username, 
readonly_schema_password=schema_password

Review Comment:
   Well, I'm not sure if we want to "lie" here. I'd say the read only columns 
could stay null and when the app starts up in a read-only mode, it smartly 
recognizes that  if not all of the readonly parameters are filled, it simply 
falls back to the normal parameters.
   Thoughts?



##########
fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0004_readonly_database_connection.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog";
+                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                   
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd";>
+    <changeSet author="fineract" 
id="add-readonly-database-connection-properties" context="tenant_store_db">
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_name" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server_port" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_username" type="VARCHAR(10)"/>

Review Comment:
   I think VARCHAR(10) is too small here. Should be VARCHAR(100) at least.



##########
fineract-provider/src/main/resources/db/changelog/tenant-store/parts/0004_readonly_database_connection.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog";
+                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                   
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog 
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd";>
+    <changeSet author="fineract" 
id="add-readonly-database-connection-properties" context="tenant_store_db">
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_name" type="VARCHAR(100)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_server_port" type="VARCHAR(10)"/>
+        </addColumn>
+        <addColumn tableName="tenant_server_connections">
+            <column name="readonly_schema_username" type="VARCHAR(10)"/>

Review Comment:
   I think VARCHAR(10) is too small here. Should be VARCHAR(100) at least.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java:
##########
@@ -80,15 +86,28 @@ public DataSource retrieveDataSource() {
     // creates the tenant data source for the oltp and report database
     private DataSource createNewDataSourceFor(final 
FineractPlatformTenantConnection tenantConnectionObj) {
         String protocol = toProtocol(this.tenantDataSource);
-        String jdbcUrl = toJdbcUrl(protocol, 
tenantConnectionObj.getSchemaServer(), 
tenantConnectionObj.getSchemaServerPort(),
-                tenantConnectionObj.getSchemaName(), 
tenantConnectionObj.getSchemaConnectionParameters());
+        // Default properties for Writing
+        String schemaServer = tenantConnectionObj.getSchemaServer();
+        String schemaPort = tenantConnectionObj.getSchemaServerPort();
+        String schemaName = tenantConnectionObj.getSchemaName();
+        String schemaUsername = tenantConnectionObj.getSchemaUsername();
+        String schemaPassword = tenantConnectionObj.getSchemaPassword();
+        // Properties to ReadOnly case
+        if (this.fineractProperties.getMode().isReadOnlyMode()) {

Review Comment:
   I know I say this all the time but this should be covered by unit tests.



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java:
##########
@@ -80,15 +86,28 @@ public DataSource retrieveDataSource() {
     // creates the tenant data source for the oltp and report database
     private DataSource createNewDataSourceFor(final 
FineractPlatformTenantConnection tenantConnectionObj) {
         String protocol = toProtocol(this.tenantDataSource);
-        String jdbcUrl = toJdbcUrl(protocol, 
tenantConnectionObj.getSchemaServer(), 
tenantConnectionObj.getSchemaServerPort(),
-                tenantConnectionObj.getSchemaName(), 
tenantConnectionObj.getSchemaConnectionParameters());
+        // Default properties for Writing
+        String schemaServer = tenantConnectionObj.getSchemaServer();
+        String schemaPort = tenantConnectionObj.getSchemaServerPort();
+        String schemaName = tenantConnectionObj.getSchemaName();
+        String schemaUsername = tenantConnectionObj.getSchemaUsername();
+        String schemaPassword = tenantConnectionObj.getSchemaPassword();
+        // Properties to ReadOnly case
+        if (this.fineractProperties.getMode().isReadOnlyMode()) {
+            schemaServer = tenantConnectionObj.getReadOnlySchemaServer();
+            schemaPort = tenantConnectionObj.getReadOnlySchemaServerPort();
+            schemaName = tenantConnectionObj.getReadOnlySchemaName();
+            schemaUsername = tenantConnectionObj.getReadOnlySchemaUsername();
+            schemaPassword = tenantConnectionObj.getReadOnlySchemaPassword();
+        }
+        String jdbcUrl = toJdbcUrl(protocol, schemaServer, schemaPort, 
schemaName, tenantConnectionObj.getSchemaConnectionParameters());

Review Comment:
   I think we should be able to provide custom connection parameters just for 
the readonly DB, dont you think?



##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java:
##########
@@ -80,15 +86,28 @@ public DataSource retrieveDataSource() {
     // creates the tenant data source for the oltp and report database
     private DataSource createNewDataSourceFor(final 
FineractPlatformTenantConnection tenantConnectionObj) {
         String protocol = toProtocol(this.tenantDataSource);
-        String jdbcUrl = toJdbcUrl(protocol, 
tenantConnectionObj.getSchemaServer(), 
tenantConnectionObj.getSchemaServerPort(),
-                tenantConnectionObj.getSchemaName(), 
tenantConnectionObj.getSchemaConnectionParameters());
+        // Default properties for Writing
+        String schemaServer = tenantConnectionObj.getSchemaServer();
+        String schemaPort = tenantConnectionObj.getSchemaServerPort();
+        String schemaName = tenantConnectionObj.getSchemaName();
+        String schemaUsername = tenantConnectionObj.getSchemaUsername();
+        String schemaPassword = tenantConnectionObj.getSchemaPassword();
+        // Properties to ReadOnly case
+        if (this.fineractProperties.getMode().isReadOnlyMode()) {

Review Comment:
   I know I say this all the time but this should be covered by unit tests.



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