Skip to content

Commit

Permalink
chore: improvements in codebase - index, migrations for postgres (app…
Browse files Browse the repository at this point in the history
…smithorg#34235)

## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes appsmithorg#34042
Fixes appsmithorg#34064
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
  • Loading branch information
vivonk authored Jun 14, 2024
1 parent a17bfb6 commit ffff1ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ private Mono<Application> createSuffixedApplication(Application application, Str
return super.create(application).onErrorResume(DataIntegrityViolationException.class, error -> {
if (error.getMessage() != null
// Catch only if error message contains workspace_app_deleted_git_application_metadata mongo error
&& (error.getMessage().contains("u_workspace_app"))) {
&& (error.getMessage()
.contains("application_workspace_name_deleted_git_application_metadata_key"))) {
if (suffix > MAX_RETRIES) {
return Mono.error(new AppsmithException(AppsmithError.DUPLICATE_KEY_PAGE_RELOAD, name));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private Mono<Datasource> createSuffixedDatasource(Datasource datasource, String
final String actualName = name + (suffix == 0 ? "" : " (" + suffix + ")");
datasource.setName(actualName);
return datasourceService.create(datasource).onErrorResume(DataIntegrityViolationException.class, error -> {
if (error.getMessage() != null && error.getMessage().contains("u_workspace_datasource")) {
if (error.getMessage() != null && error.getMessage().contains("datasource_workspace_name_deleted_key")) {
return createSuffixedDatasource(datasource, name, 1 + suffix);
}
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ private void moveForTable(Path jsonlPath, JdbcTemplate jdbcTemplate, boolean isC
}
}

if (columnTypes.containsKey("created_at")) {
data.put("created_at", Instant.now().toString());
}
if (columnTypes.containsKey("updated_at")) {
data.put("updated_at", null);
}

// Build the INSERT query to only have the columns that are present in the JSON document. This allows
// the rest of the columns to take on their default value, if configured, instead of `null`.
final String sql = String.join(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
create unique index if not exists u_name_config on config(name);
create unique index if not exists u_email_pass_reset_token on password_reset_token(email);
create unique index if not exists u_email_user on "user"(email);
create unique index if not exists u_name_sequence on sequence(name);
create unique index if not exists plugin_name_package_name_version_index on plugin(plugin_name, package_name, version);
create unique index if not exists u_user_id on user_data(user_id);
create unique index if not exists u_workspace_datasource_deleted on datasource(workspace_id, name, deleted_at);
CREATE UNIQUE INDEX if not exists u_workspace_datasource ON datasource (workspace_id, name) WHERE deleted_at IS NULL;
create unique index if not exists u_workspace_app_deleted on application(workspace_id, name, deleted_at) where git_application_metadata is null;
create unique index if not exists u_workspace_app on application(workspace_id, name) where deleted_at is null and git_application_metadata is null;
create unique index if not exists u_workspace_app_deleted_git_application_metadata on application(workspace_id, name, deleted_at, (git_application_metadata ->> 'remoteUrl'), (git_application_metadata ->>'branchName'));
create unique index if not exists u_workspace_app_git_application_metadata on application(workspace_id, name, (git_application_metadata ->> 'remoteUrl'), (git_application_metadata ->>'branchName')) WHERE deleted_at is NULL;
create unique index if not exists u_dsConfigStructure_dsId_envId on datasource_storage_structure(datasource_id, environment_id);
create unique index if not exists u_applicationId_chunkOrder on application_snapshot(application_id, chunk_order);
-- index naming convention: (pkey reserved for primary keys)
-- unique constraint index - table_name_column_name_key
-- performance improvement index - table_name_column_name_idx
create unique index if not exists config_name_key on config(name) ;
create unique index if not exists prt_email_key on password_reset_token(email);
create unique index if not exists user_email_key on "user"(email);
create unique index if not exists sequence_name_key on sequence(name);
create unique index if not exists plugin_name_package_name_version_key on plugin(plugin_name, package_name, version) NULLS NOT DISTINCT;
create unique index if not exists user_id_key on user_data(user_id);
create unique index if not exists datasource_workspace_name_deleted_key on datasource(workspace_id, name, deleted_at) NULLS NOT DISTINCT;
create unique index if not exists application_workspace_name_deleted_git_application_metadata_key on application(workspace_id, name, deleted_at, (git_application_metadata ->> 'remoteUrl'), (git_application_metadata ->>'branchName')) NULLS NOT DISTINCT;
create unique index if not exists dss_datasource_env_key on datasource_storage_structure(datasource_id, environment_id) NULLS NOT DISTINCT;
create unique index if not exists application_snapshot_application_chunkOrder_key on application_snapshot(application_id, chunk_order) NULLS NOT DISTINCT;
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private Mono<Datasource> createSuffixedDatasource(
final String finalPassword = password;
return datasourceService.create(datasource).onErrorResume(DataIntegrityViolationException.class, error -> {
if (error.getMessage() != null
&& error.getMessage().contains("u_workspace_datasource")
&& error.getMessage().contains("datasource_workspace_name_deleted_key")
&& datasourceStorageDTO.getDatasourceConfiguration().getAuthentication() instanceof DBAuth) {
((DBAuth) datasourceStorageDTO.getDatasourceConfiguration().getAuthentication())
.setPassword(finalPassword);
Expand Down

0 comments on commit ffff1ef

Please sign in to comment.