@@ -140,28 +140,35 @@ const (
140140
141141func runMigrations (databaseURL string ) error {
142142 // Change the driver to pgx5
143- databaseURL = "pgx5://" + strings .TrimPrefix (databaseURL , "postgres://" )
144-
145- // Create migration source from embedded files
146- d , err := iofs .New (migrationFiles , "migrations" )
147- if err != nil {
148- return newInitializationError (fmt .Sprintf ("failed to create migration source: %v" , err ))
149- }
150-
151- // Add custom migration table name to avoid conflicts with user migrations
152- // Parse the URL to properly determine where to add the query parameter
153143 parsedURL , err := url .Parse (databaseURL )
154144 if err != nil {
155145 return newInitializationError (fmt .Sprintf ("failed to parse database URL: %v" , err ))
156146 }
147+ // Handle various PostgreSQL URL schemes
148+ switch parsedURL .Scheme {
149+ case "postgres" , "postgresql" :
150+ parsedURL .Scheme = "pgx5"
151+ case "pgx5" :
152+ // Already in correct format
153+ default :
154+ return newInitializationError (fmt .Sprintf ("unsupported database URL scheme: %s" , parsedURL .Scheme ))
155+ }
156+ databaseURL = parsedURL .String ()
157157
158+ // Add custom migration table name to avoid conflicts with user migrations
158159 // Check if query parameters already exist
159160 separator := "?"
160161 if parsedURL .RawQuery != "" {
161162 separator = "&"
162163 }
163164 databaseURL += separator + "x-migrations-table=" + _DBOS_MIGRATION_TABLE
164165
166+ // Create migration source from embedded files
167+ d , err := iofs .New (migrationFiles , "migrations" )
168+ if err != nil {
169+ return newInitializationError (fmt .Sprintf ("failed to create migration source: %v" , err ))
170+ }
171+
165172 // Create migrator
166173 m , err := migrate .NewWithSourceInstance ("iofs" , d , databaseURL )
167174 if err != nil {
0 commit comments