@@ -41,9 +41,15 @@ func runMigrate(cmd *cobra.Command, args []string) error {
4141 return fmt .Errorf ("failed to create DBOS context: %w" , err )
4242 }
4343
44+ // Determine the schema to use (from flag or default)
45+ dbSchema := "dbos"
46+ if schema != "" {
47+ dbSchema = schema
48+ }
49+
4450 // Grant permissions to application role if specified
4551 if applicationRole != "" {
46- if err := grantDBOSSchemaPermissions (dbURL , applicationRole ); err != nil {
52+ if err := grantDBOSSchemaPermissions (dbURL , applicationRole , dbSchema ); err != nil {
4753 return err
4854 }
4955 }
@@ -74,8 +80,8 @@ func runMigrate(cmd *cobra.Command, args []string) error {
7480 return nil
7581}
7682
77- func grantDBOSSchemaPermissions (databaseURL , roleName string ) error {
78- logger .Info ("Granting permissions for DBOS schema" , "role" , roleName )
83+ func grantDBOSSchemaPermissions (databaseURL , roleName , schemaName string ) error {
84+ logger .Info ("Granting permissions for schema" , "role" , roleName , "schema" , schemaName )
7985
8086 db , err := sql .Open ("pgx" , databaseURL )
8187 if err != nil {
@@ -86,15 +92,15 @@ func grantDBOSSchemaPermissions(databaseURL, roleName string) error {
8692 ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
8793 defer cancel ()
8894
89- // Grant usage on the dbos schema
95+ // Grant usage on the specified schema
9096 queries := []string {
91- fmt .Sprintf (`GRANT USAGE ON SCHEMA dbos TO "%s"` , roleName ),
92- fmt .Sprintf (`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA dbos TO "%s"` , roleName ),
93- fmt .Sprintf (`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA dbos TO "%s"` , roleName ),
94- fmt .Sprintf (`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA dbos TO "%s"` , roleName ),
95- fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA dbos GRANT ALL ON TABLES TO "%s"` , roleName ),
96- fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA dbos GRANT ALL ON SEQUENCES TO "%s"` , roleName ),
97- fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA dbos GRANT EXECUTE ON FUNCTIONS TO "%s"` , roleName ),
97+ fmt .Sprintf (`GRANT USAGE ON SCHEMA %s TO "%s"` , schemaName , roleName ),
98+ fmt .Sprintf (`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA %s TO "%s"` , schemaName , roleName ),
99+ fmt .Sprintf (`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA %s TO "%s"` , schemaName , roleName ),
100+ fmt .Sprintf (`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA %s TO "%s"` , schemaName , roleName ),
101+ fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA %s GRANT ALL ON TABLES TO "%s"` , schemaName , roleName ),
102+ fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA %s GRANT ALL ON SEQUENCES TO "%s"` , schemaName , roleName ),
103+ fmt .Sprintf (`ALTER DEFAULT PRIVILEGES IN SCHEMA %s GRANT EXECUTE ON FUNCTIONS TO "%s"` , schemaName , roleName ),
98104 }
99105
100106 for _ , query := range queries {
0 commit comments