Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improvements in codebase - index, migrations for postgres #34235

Merged
merged 4 commits into from
Jun 14, 2024
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
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
Loading