Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 7 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 68 additions & 0 deletions src/main/resources/db/migration/postgresql/V1__Initial_Setup.sql
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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', '');
Original file line number Diff line number Diff line change
@@ -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', '');
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Loading