diff --git a/build.gradle b/build.gradle index 049901d3..30acc846 100644 --- a/build.gradle +++ b/build.gradle @@ -57,6 +57,8 @@ dependencies { // flyway-core into its own module. The migrations in db/migration are MySQL. implementation 'org.flywaydb:flyway-mysql' runtimeOnly 'com.mysql:mysql-connector-j' + implementation 'org.flywaydb:flyway-database-postgresql' + runtimeOnly 'org.postgresql:postgresql' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' implementation 'org.json:json' diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fcbcc213..fb815b75 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,10 +16,13 @@ spring: ddl-auto: none datasource: - url: jdbc:mysql:thin://operations-mysql:3306/messagegateway - username: ${MYSQL_USERNAME:root} - password: ${MYSQL_PASSWORD:password} - driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL:jdbc:postgresql://localhost:5432/messagegateway} + username: ${DB_USERNAME:postgres} + password: ${DB_PASSWORD:password} + driver-class-name: ${DB_DRIVER:org.postgresql.Driver} + + flyway: + locations: classpath:db/migration/{vendor} # Status Callback configuration for Twilio. Port will be taken from server configuration hostconfig: diff --git a/src/main/resources/db/migration/V1__Initial_Setup.sql b/src/main/resources/db/migration/mysql/V1__Initial_Setup.sql similarity index 100% rename from src/main/resources/db/migration/V1__Initial_Setup.sql rename to src/main/resources/db/migration/mysql/V1__Initial_Setup.sql diff --git a/src/main/resources/db/migration/V2__response_code_to_mesages.sql b/src/main/resources/db/migration/mysql/V2__response_code_to_mesages.sql similarity index 100% rename from src/main/resources/db/migration/V2__response_code_to_mesages.sql rename to src/main/resources/db/migration/mysql/V2__response_code_to_mesages.sql diff --git a/src/main/resources/db/migration/V3__Adding _New_Provider.sql b/src/main/resources/db/migration/mysql/V3__Adding _New_Provider.sql similarity index 100% rename from src/main/resources/db/migration/V3__Adding _New_Provider.sql rename to src/main/resources/db/migration/mysql/V3__Adding _New_Provider.sql diff --git a/src/main/resources/db/migration/V4__Adding _RapidPro_Provider.sql b/src/main/resources/db/migration/mysql/V4__Adding _RapidPro_Provider.sql similarity index 100% rename from src/main/resources/db/migration/V4__Adding _RapidPro_Provider.sql rename to src/main/resources/db/migration/mysql/V4__Adding _RapidPro_Provider.sql diff --git a/src/main/resources/db/migration/V5__Adding _Telerivet_ProviderConfigurations.sql b/src/main/resources/db/migration/mysql/V5__Adding _Telerivet_ProviderConfigurations.sql similarity index 100% rename from src/main/resources/db/migration/V5__Adding _Telerivet_ProviderConfigurations.sql rename to src/main/resources/db/migration/mysql/V5__Adding _Telerivet_ProviderConfigurations.sql diff --git a/src/main/resources/db/migration/V6__Updating_Default_DateValue.sql b/src/main/resources/db/migration/mysql/V6__Updating_Default_DateValue.sql similarity index 100% rename from src/main/resources/db/migration/V6__Updating_Default_DateValue.sql rename to src/main/resources/db/migration/mysql/V6__Updating_Default_DateValue.sql diff --git a/src/main/resources/db/migration/V7__Updating_DefaultValue_forDate.sql b/src/main/resources/db/migration/mysql/V7__Updating_DefaultValue_forDate.sql similarity index 100% rename from src/main/resources/db/migration/V7__Updating_DefaultValue_forDate.sql rename to src/main/resources/db/migration/mysql/V7__Updating_DefaultValue_forDate.sql diff --git a/src/main/resources/db/migration/V8__Updating_Outbound_Message_Schema.sql b/src/main/resources/db/migration/mysql/V8__Updating_Outbound_Message_Schema.sql similarity index 100% rename from src/main/resources/db/migration/V8__Updating_Outbound_Message_Schema.sql rename to src/main/resources/db/migration/mysql/V8__Updating_Outbound_Message_Schema.sql diff --git a/src/main/resources/db/migration/postgresql/V1__Initial_Setup.sql b/src/main/resources/db/migration/postgresql/V1__Initial_Setup.sql new file mode 100644 index 00000000..6517dbbb --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V1__Initial_Setup.sql @@ -0,0 +1,68 @@ +-- +-- 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. +-- + +CREATE TABLE m_tenants ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + tenant_id VARCHAR(32) NOT NULL, + tenant_app_key VARCHAR(100) NOT NULL, + description VARCHAR(500) DEFAULT NULL +); + +CREATE TABLE m_sms_bridge ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + tenant_id BIGINT NOT NULL, + tenant_phone_no VARCHAR(255) NOT NULL, + provider_name VARCHAR(100) NOT NULL, + country_code VARCHAR(5) NOT NULL, + provider_key VARCHAR(100) NOT NULL, + description VARCHAR(500) NOT NULL, + created_on TIMESTAMP DEFAULT NULL, + last_modified_on TIMESTAMP DEFAULT NULL, + CONSTRAINT m_sms_bridge_1 FOREIGN KEY (tenant_id) REFERENCES m_tenants (id) +); + +CREATE TABLE m_outbound_messages ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + tenant_id VARCHAR(32) NOT NULL, + external_id VARCHAR(100) DEFAULT NULL, + internal_id VARCHAR(100) NOT NULL, + delivery_error_message VARCHAR(500) DEFAULT NULL, + source_address VARCHAR(100) DEFAULT NULL, + sms_bridge_id BIGINT NOT NULL, + mobile_number VARCHAR(255) NOT NULL, + submitted_on_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + delivered_on_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + delivery_status INTEGER NOT NULL, + message VARCHAR(4096) NOT NULL, + CONSTRAINT m_outbound_messages_1 FOREIGN KEY (sms_bridge_id) REFERENCES m_sms_bridge (id) +); + +CREATE TABLE m_sms_bridge_configuration ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + sms_bridge_id BIGINT NOT NULL, + config_name VARCHAR(100) DEFAULT NULL, + config_value VARCHAR(100) NOT NULL, + CONSTRAINT m_provider_configuration_1 FOREIGN KEY (sms_bridge_id) REFERENCES m_sms_bridge (id) +); + +INSERT INTO m_tenants (tenant_id, tenant_app_key, description) +VALUES ('default', '123456543234abdkdkdkd', 'TEST TENANT'); + +INSERT INTO m_sms_bridge (tenant_id, tenant_phone_no, provider_key, country_code, provider_name, description) +VALUES (1, '+1234567890', 'Dummy', '+91', 'Dummy SMS Provider - Testing', 'Dummy, just for testing'); diff --git a/src/main/resources/db/migration/postgresql/V2__response_code_to_messages.sql b/src/main/resources/db/migration/postgresql/V2__response_code_to_messages.sql new file mode 100644 index 00000000..0a696432 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V2__response_code_to_messages.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +ALTER TABLE m_outbound_messages ADD COLUMN response VARCHAR(200) DEFAULT NULL; diff --git a/src/main/resources/db/migration/postgresql/V3__Add_New_Provider.sql b/src/main/resources/db/migration/postgresql/V3__Add_New_Provider.sql new file mode 100644 index 00000000..5de419f1 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V3__Add_New_Provider.sql @@ -0,0 +1,21 @@ +-- +-- 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. +-- + +INSERT INTO m_sms_bridge (tenant_id, tenant_phone_no, provider_key, country_code, provider_name, description) +VALUES ((SELECT id FROM m_tenants WHERE tenant_id = 'default'), '555-1212', 'telerivet', '+91', 'Telerivet', 'Telerivet Messenger'); diff --git a/src/main/resources/db/migration/postgresql/V4__Add_RapidPro_Provider.sql b/src/main/resources/db/migration/postgresql/V4__Add_RapidPro_Provider.sql new file mode 100644 index 00000000..a1689363 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V4__Add_RapidPro_Provider.sql @@ -0,0 +1,27 @@ +-- +-- 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. +-- + +INSERT INTO m_sms_bridge (tenant_id, tenant_phone_no, provider_key, country_code, provider_name, description) +VALUES ((SELECT id FROM m_tenants WHERE tenant_id = 'default'), '555-1212', 'RapidPro', '+91', 'RapidPro', 'RapidPro Messenger'); + +INSERT INTO m_sms_bridge_configuration (sms_bridge_id, config_name, config_value) +VALUES ((SELECT id FROM m_sms_bridge WHERE provider_key = 'RapidPro'), 'Provider_Url', 'https://api.rapidpro.io/api/v2'); + +INSERT INTO m_sms_bridge_configuration (sms_bridge_id, config_name, config_value) +VALUES ((SELECT id FROM m_sms_bridge WHERE provider_key = 'RapidPro'), 'Provider_Auth_Token', ''); diff --git a/src/main/resources/db/migration/postgresql/V5__Add_Telerivet_ProviderConfigurations.sql b/src/main/resources/db/migration/postgresql/V5__Add_Telerivet_ProviderConfigurations.sql new file mode 100644 index 00000000..85c49688 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V5__Add_Telerivet_ProviderConfigurations.sql @@ -0,0 +1,24 @@ +-- +-- 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. +-- + +INSERT INTO m_sms_bridge_configuration (sms_bridge_id, config_name, config_value) +VALUES ((SELECT id FROM m_sms_bridge WHERE provider_key = 'telerivet'), 'Provider_API_Key', ''); + +INSERT INTO m_sms_bridge_configuration (sms_bridge_id, config_name, config_value) +VALUES ((SELECT id FROM m_sms_bridge WHERE provider_key = 'telerivet'), 'Provider_Project_Id', ''); diff --git a/src/main/resources/db/migration/postgresql/V6__Update_Default_DateValue.sql b/src/main/resources/db/migration/postgresql/V6__Update_Default_DateValue.sql new file mode 100644 index 00000000..bfd9b35d --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V6__Update_Default_DateValue.sql @@ -0,0 +1,23 @@ +-- +-- 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. +-- + +ALTER TABLE m_outbound_messages ALTER COLUMN submitted_on_date SET DEFAULT CURRENT_TIMESTAMP; +ALTER TABLE m_outbound_messages ALTER COLUMN submitted_on_date SET NOT NULL; +ALTER TABLE m_outbound_messages ALTER COLUMN delivered_on_date SET DEFAULT CURRENT_TIMESTAMP; +ALTER TABLE m_outbound_messages ALTER COLUMN delivered_on_date SET NOT NULL; diff --git a/src/main/resources/db/migration/postgresql/V7__Update_DefaultValue_forDate.sql b/src/main/resources/db/migration/postgresql/V7__Update_DefaultValue_forDate.sql new file mode 100644 index 00000000..b1be5679 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V7__Update_DefaultValue_forDate.sql @@ -0,0 +1,23 @@ +-- +-- 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. +-- + +ALTER TABLE m_outbound_messages ALTER COLUMN submitted_on_date DROP NOT NULL; +ALTER TABLE m_outbound_messages ALTER COLUMN submitted_on_date SET DEFAULT CURRENT_TIMESTAMP; +ALTER TABLE m_outbound_messages ALTER COLUMN delivered_on_date DROP NOT NULL; +ALTER TABLE m_outbound_messages ALTER COLUMN delivered_on_date SET DEFAULT CURRENT_TIMESTAMP; diff --git a/src/main/resources/db/migration/postgresql/V8__Update_Outbound_Message_Schema.sql b/src/main/resources/db/migration/postgresql/V8__Update_Outbound_Message_Schema.sql new file mode 100644 index 00000000..ea1462b4 --- /dev/null +++ b/src/main/resources/db/migration/postgresql/V8__Update_Outbound_Message_Schema.sql @@ -0,0 +1,22 @@ +-- +-- 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. +-- + +ALTER TABLE m_outbound_messages ADD COLUMN email TEXT DEFAULT NULL; +ALTER TABLE m_outbound_messages ADD COLUMN type VARCHAR(30) NOT NULL DEFAULT ''; +ALTER TABLE m_outbound_messages ALTER COLUMN message DROP NOT NULL;