@@ -34,11 +34,13 @@ extern char *ApiExtensionName;
3434extern char * ApiGucPrefix ;
3535extern char * ClusterAdminRole ;
3636
37- char * ApiDistributedSchemaName = "helio_api_distributed " ;
38- char * DistributedExtensionName = "pg_helio_distributed " ;
37+ char * ApiDistributedSchemaName = "documentdb_api_distributed " ;
38+ char * DistributedExtensionName = "documentdb_distributed " ;
3939bool CreateDistributedFunctions = false;
4040bool CreateIndexBuildQueueTable = false;
4141
42+ extern char * GetIndexQueueName (void );
43+
4244static char * GetClusterInitializedVersion (void );
4345static void DistributeCrudFunctions (void );
4446static void ScheduleIndexBuildTasks (char * extensionPrefix );
@@ -62,7 +64,7 @@ static bool VersionEquals(ExtensionVersion versionA, ExtensionVersion versionB);
6264static void GetInstalledVersion (ExtensionVersion * installedVersion );
6365static void ParseVersionString (ExtensionVersion * extensionVersion , char * versionString );
6466static bool SetupCluster (bool isInitialize );
65- static void SetPermissionsForHelioReadOnlyRole (void );
67+ static void SetPermissionsForReadOnlyRole (void );
6668static ArrayType * GetCollectionIds (void );
6769
6870PG_FUNCTION_INFO_V1 (command_initialize_cluster );
@@ -225,7 +227,7 @@ SetupCluster(bool isInitialize)
225227 char * oldExtensionPrefix = ExtensionObjectPrefix ;
226228 UnscheduleIndexBuildTasks (oldExtensionPrefix );
227229
228- char * extensionPrefix = "helio" ;
230+ char * extensionPrefix = ExtensionObjectPrefixV2 ;
229231 ScheduleIndexBuildTasks (extensionPrefix );
230232 }
231233
@@ -238,14 +240,14 @@ SetupCluster(bool isInitialize)
238240 if (ShouldRunSetupForVersion (lastUpgradeVersion , installedVersion , DocDB_V0 , 15 , 0 ))
239241 {
240242 /* reduce the Index background cron job schedule to 2 seconds by default. */
241- char * extensionPrefix = "helio" ;
243+ char * extensionPrefix = ExtensionObjectPrefixV2 ;
242244 UnscheduleIndexBuildTasks (extensionPrefix );
243245 ScheduleIndexBuildTasks (extensionPrefix );
244246 }
245247
246248 if (ShouldRunSetupForVersion (lastUpgradeVersion , installedVersion , DocDB_V0 , 17 , 1 ))
247249 {
248- SetPermissionsForHelioReadOnlyRole ();
250+ SetPermissionsForReadOnlyRole ();
249251 }
250252
251253 if (ShouldRunSetupForVersion (lastUpgradeVersion , installedVersion , DocDB_V0 , 21 , 0 ))
@@ -255,7 +257,9 @@ SetupCluster(bool isInitialize)
255257 StringInfo cmdStr = makeStringInfo ();
256258 bool isNull = false;
257259 appendStringInfo (cmdStr ,
258- "GRANT helio_admin_role, helio_readonly_role TO %s WITH ADMIN OPTION;" ,
260+ "GRANT %s, %s TO %s WITH ADMIN OPTION;" ,
261+ ApiAdminRoleV2 ,
262+ ApiReadOnlyRole ,
259263 quote_identifier (ClusterAdminRole ));
260264 ExtensionExecuteQueryViaSPI (cmdStr -> data , false, SPI_OK_UTILITY ,
261265 & isNull );
@@ -443,13 +447,13 @@ CreateIndexBuildQueueCore()
443447
444448 StringInfo dropStr = makeStringInfo ();
445449 appendStringInfo (dropStr ,
446- "DROP TABLE IF EXISTS helio_api_catalog.helio_index_queue;" );
450+ "DROP TABLE IF EXISTS %s;" , GetIndexQueueName () );
447451 ExtensionExecuteQueryViaSPI (dropStr -> data , readOnly , SPI_OK_UTILITY ,
448452 & isNull );
449453
450454 StringInfo createStr = makeStringInfo ();
451455 appendStringInfo (createStr ,
452- "CREATE TABLE IF NOT EXISTS helio_api_catalog.helio_index_queue ("
456+ "CREATE TABLE IF NOT EXISTS %s ("
453457 "index_cmd text not null,"
454458
455459 /* 'C' for CREATE INDEX and 'R' for REINDEX */
@@ -471,32 +475,36 @@ CreateIndexBuildQueueCore()
471475 /* update_time shows the time when request was updated in the table */
472476 "update_time timestamp with time zone DEFAULT now()"
473477
474- ")" , CoreSchemaName );
478+ ")" , GetIndexQueueName (), CoreSchemaName );
475479
476480 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_UTILITY ,
477481 & isNull );
478482
479483 resetStringInfo (createStr );
480484 appendStringInfo (createStr ,
481- "CREATE INDEX IF NOT EXISTS helio_index_queue_indexid_cmdtype on helio_api_catalog.helio_index_queue (index_id, cmd_type)" );
485+ "CREATE INDEX IF NOT EXISTS %s_index_queue_indexid_cmdtype on %s (index_id, cmd_type)" ,
486+ ExtensionObjectPrefixV2 , GetIndexQueueName ());
482487 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_UTILITY ,
483488 & isNull );
484489
485490 resetStringInfo (createStr );
486491 appendStringInfo (createStr ,
487- "CREATE INDEX IF NOT EXISTS helio_index_queue_cmdtype_collectionid_cmdstatus on helio_api_catalog.helio_index_queue (cmd_type, collection_id, index_cmd_status)" );
492+ "CREATE INDEX IF NOT EXISTS %s_index_queue_cmdtype_collectionid_cmdstatus on %s (cmd_type, collection_id, index_cmd_status)" ,
493+ ExtensionObjectPrefixV2 , GetIndexQueueName ());
488494 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_UTILITY ,
489495 & isNull );
490496
491497 resetStringInfo (createStr );
492498 appendStringInfo (createStr ,
493- "GRANT SELECT ON TABLE helio_api_catalog.helio_index_queue TO public" );
499+ "GRANT SELECT ON TABLE %s TO public" , GetIndexQueueName () );
494500 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_UTILITY ,
495501 & isNull );
496502
497503 resetStringInfo (createStr );
498504 appendStringInfo (createStr ,
499- "GRANT ALL ON TABLE helio_api_catalog.helio_index_queue TO helio_admin_role, %s" ,
505+ "GRANT ALL ON TABLE %s TO %s, %s" ,
506+ GetIndexQueueName (),
507+ ApiAdminRoleV2 ,
500508 ApiAdminRole );
501509 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_UTILITY ,
502510 & isNull );
@@ -519,7 +527,8 @@ CreateIndexBuildsTable()
519527 bool isNull = false;
520528 StringInfo createStr = makeStringInfo ();
521529 appendStringInfo (createStr ,
522- "SELECT citus_add_local_table_to_metadata('helio_api_catalog.helio_index_queue')" );
530+ "SELECT citus_add_local_table_to_metadata('%s')" ,
531+ GetIndexQueueName ());
523532 ExtensionExecuteQueryViaSPI (createStr -> data , readOnly , SPI_OK_SELECT ,
524533 & isNull );
525534}
@@ -802,20 +811,23 @@ AddUserColumnsToIndexQueue()
802811
803812 StringInfo cmdStr = makeStringInfo ();
804813 appendStringInfo (cmdStr ,
805- "ALTER TABLE helio_api_catalog.helio_index_queue ADD COLUMN IF NOT EXISTS user_oid Oid;" );
814+ "ALTER TABLE %s ADD COLUMN IF NOT EXISTS user_oid Oid;" ,
815+ GetIndexQueueName ());
806816 ExtensionExecuteQueryViaSPI (cmdStr -> data , readOnly , SPI_OK_UTILITY ,
807817 & isNull );
808818
809819 /* We first drop the check constraint if it already exists. Some upgrade paths can create it before this function is executed. */
810820 resetStringInfo (cmdStr );
811821 appendStringInfo (cmdStr ,
812- "ALTER TABLE helio_api_catalog.helio_index_queue DROP CONSTRAINT IF EXISTS helio_index_queue_user_oid_check;" );
822+ "ALTER TABLE %s DROP CONSTRAINT IF EXISTS %s_index_queue_user_oid_check;" ,
823+ GetIndexQueueName (), ExtensionObjectPrefixV2 );
813824 ExtensionExecuteQueryViaSPI (cmdStr -> data , readOnly , SPI_OK_UTILITY ,
814825 & isNull );
815826
816827 resetStringInfo (cmdStr );
817828 appendStringInfo (cmdStr ,
818- "ALTER TABLE helio_api_catalog.helio_index_queue ADD CONSTRAINT helio_index_queue_user_oid_check CHECK (user_oid IS NULL OR user_oid != '0'::oid);" );
829+ "ALTER TABLE %s ADD CONSTRAINT %s_index_queue_user_oid_check CHECK (user_oid IS NULL OR user_oid != '0'::oid);" ,
830+ GetIndexQueueName (), ExtensionObjectPrefixV2 );
819831 ExtensionExecuteQueryViaSPI (cmdStr -> data , readOnly , SPI_OK_UTILITY ,
820832 & isNull );
821833}
@@ -914,18 +926,18 @@ GetInstalledVersion(ExtensionVersion *installedVersion)
914926
915927
916928/*
917- * SetPermissionsForHelioReadOnlyRole - Set the right permissions for helio_readonly_role
929+ * SetPermissionsForReadOnlyRole - Set the right permissions for ApiReadOnlyRole
918930 */
919931static void
920- SetPermissionsForHelioReadOnlyRole ()
932+ SetPermissionsForReadOnlyRole ()
921933{
922934 bool readOnly = false;
923935 bool isNull = false;
924936 StringInfo cmdStr = makeStringInfo ();
925937
926938 appendStringInfo (cmdStr ,
927- "GRANT SELECT ON TABLE %s.%s_cluster_data TO helio_readonly_role ;" ,
928- ApiDistributedSchemaName , ExtensionObjectPrefix );
939+ "GRANT SELECT ON TABLE %s.%s_cluster_data TO %s ;" ,
940+ ApiDistributedSchemaName , ExtensionObjectPrefix , ApiReadOnlyRole );
929941 ExtensionExecuteQueryViaSPI (cmdStr -> data , readOnly , SPI_OK_UTILITY ,
930942 & isNull );
931943
@@ -946,8 +958,8 @@ SetPermissionsForHelioReadOnlyRole()
946958 int collection_id = DatumGetInt32 (elements [i ]);
947959 resetStringInfo (cmdStr );
948960 appendStringInfo (cmdStr ,
949- "GRANT SELECT ON %s.documents_%d TO helio_readonly_role ;" ,
950- ApiDataSchemaName , collection_id );
961+ "GRANT SELECT ON %s.documents_%d TO %s ;" ,
962+ ApiDataSchemaName , collection_id , ApiReadOnlyRole );
951963 ExtensionExecuteQueryViaSPI (cmdStr -> data , readOnly , SPI_OK_UTILITY ,
952964 & isNull );
953965 }
@@ -992,8 +1004,10 @@ UpdateClusterMetadata(bool isInitialize)
9921004
9931005 Datum clusterVersionDatum = ExtensionExecuteQueryViaSPI (
9941006 FormatSqlQuery (
995- "SELECT helio_core.bson_get_value_text(metadata, 'last_deploy_version') FROM %s.%s_cluster_data" ,
996- ApiDistributedSchemaName , ExtensionObjectPrefix ), true, SPI_OK_SELECT ,
1007+ "SELECT %s.bson_get_value_text(metadata, 'last_deploy_version') FROM %s.%s_cluster_data" ,
1008+ CoreSchemaNameV2 , ApiDistributedSchemaName , ExtensionObjectPrefix ),
1009+ true,
1010+ SPI_OK_SELECT ,
9971011 & isNull );
9981012 Assert (!isNull );
9991013
0 commit comments