chore: remove the redirection for mockdb to localhost (#28998)

## Description
This PR fixes the experience of Templates forking in self hosted
instances. And also for to Set up a process to keep the embedded DB up
to date with template db schemas.
We have removed the redirection of mockdb end point used in templates
App when forked in self hosted instance from localhost/internal postgres
db.
This also has a migration which is to make sure that none of existing
apps using the internal postgres does not break due to the removal of
redirection. The migration will make sure that existing self hosted
instances using the posgress db and has a datasource with mockdb end
point will be replaces with localhost.


#### PR fixes following issue(s)
Fixes https://github.com/appsmithorg/appsmith/issues/28924

#### Type of change
- Bug fix (non-breaking change which fixes an issue)

## Testing

#### How Has This Been Tested?
- [ ] Manual

#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
Anagh Hegde 2023-11-24 17:32:09 +05:30 committed by GitHub
parent 5a250ac650
commit c764d4471b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 2 deletions

View File

@ -0,0 +1,53 @@
package com.appsmith.server.migrations.db.ce;
import com.appsmith.external.models.DatasourceStorage;
import com.appsmith.server.configurations.CommonConfig;
import com.appsmith.server.solutions.EnvManager;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import io.mongock.api.annotations.RollbackExecution;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.core.query.Update.update;
@Slf4j
@ChangeUnit(order = "035", id = "remove-mockdb-endpoint-in-datasource-self-hosted-instance", author = " ")
public class Migration035RemoveMockDbEndPointInDatasourceInSelfHostedInstance {
private final MongoTemplate mongoTemplate;
private final CommonConfig commonConfig;
private final EnvManager envManager;
public Migration035RemoveMockDbEndPointInDatasourceInSelfHostedInstance(
MongoTemplate mongoTemplate, CommonConfig commonConfig, EnvManager envManager) {
this.mongoTemplate = mongoTemplate;
this.commonConfig = commonConfig;
this.envManager = envManager;
}
@RollbackExecution
public void rollbackExecution() {}
@Execution
public void removeMockDbEndpointInDatasource() {
// This migration is applicable for self-hosted instances only.
// The end point used in templates is redirected to internal postgres db
// We are now switching to RDS and hence want to remove this endpoint from the datasource and replace it with
// localhost, so that the existing queries do not break. And the data stored in the db by users is not lost
// APPSMITH_ENABLE_EMBEDDED_DB && isCloudHosting
boolean isEmbeddedDbEnabled = !"0".equals(System.getenv("APPSMITH_ENABLE_EMBEDDED_DB"));
if (isEmbeddedDbEnabled && Boolean.FALSE.equals(commonConfig.isCloudHosting())) {
mongoTemplate.updateMulti(
query(where("datasourceConfiguration.endpoints.host").is("mockdb.internal.appsmith.com")),
update("datasourceConfiguration.endpoints.$.host", "127.0.0.1"),
DatasourceStorage.class);
}
}
}

View File

@ -354,8 +354,6 @@ configure_supervisord() {
fi
if [[ $runEmbeddedPostgres -eq 1 ]]; then
cp "$supervisord_conf_source/postgres.conf" "$SUPERVISORD_CONF_TARGET"
# Update hosts lookup to resolve to embedded postgres
echo '127.0.0.1 mockdb.internal.appsmith.com' >> /etc/hosts
fi
fi