@@ -201,6 +201,23 @@ func FromFS(ctx context.Context, session gocqlx.Session, f fs.FS) error {
201201 return nil
202202}
203203
204+ // applyMigration executes a single migration file by parsing and applying its statements.
205+ // It handles three types of content in migration files:
206+ // - SQL statements: executed against the database
207+ // - Callback commands: processed via registered callback handlers (format: -- CALL function_name;)
208+ // - Regular comments: silently skipped (format: -- any comment text)
209+ //
210+ // The function maintains migration state by tracking the number of completed statements,
211+ // allowing for resumption of partially completed migrations.
212+ //
213+ // Parameters:
214+ // - ctx: context for cancellation and timeouts
215+ // - session: database session for executing statements
216+ // - f: filesystem containing the migration file
217+ // - path: path to the migration file within the filesystem
218+ // - done: number of statements already completed (for resuming partial migrations)
219+ //
220+ // Returns an error if the migration fails at any point.
204221func applyMigration (ctx context.Context , session gocqlx.Session , f fs.FS , path string , done int ) error {
205222 file , err := f .Open (path )
206223 if err != nil {
@@ -272,19 +289,23 @@ func applyMigration(ctx context.Context, session gocqlx.Session, f fs.FS, path s
272289 // trim new lines and all whitespace characters
273290 stmt = strings .TrimSpace (stmt )
274291
292+ // Process statement based on its type
275293 if cb := isCallback (stmt ); cb != "" {
294+ // Handle callback commands (e.g., "-- CALL function_name;")
276295 if Callback == nil {
277296 return fmt .Errorf ("statement %d: missing callback handler while trying to call %s" , i , cb )
278297 }
279298 if err := Callback (ctx , session , CallComment , cb ); err != nil {
280299 return fmt .Errorf ("callback %s: %s" , cb , err )
281300 }
282- } else {
301+ } else if stmt != "" && ! isComment (stmt ) {
302+ // Execute SQL statements (skip empty statements and comments)
283303 q := session .ContextQuery (ctx , stmt , nil ).RetryPolicy (nil )
284304 if err := q .ExecRelease (); err != nil {
285305 return fmt .Errorf ("statement %d: %s" , i , err )
286306 }
287307 }
308+ // Regular comments and empty statements are silently skipped
288309
289310 // update info
290311 info .Done = i
@@ -315,3 +336,10 @@ func isCallback(stmt string) (name string) {
315336 }
316337 return s [1 ]
317338}
339+
340+ // isComment returns true if the statement is a SQL comment that should be ignored.
341+ // It distinguishes between regular comments (which should be skipped) and
342+ // callback commands (which should be processed).
343+ func isComment (stmt string ) bool {
344+ return strings .HasPrefix (stmt , "--" ) && isCallback (stmt ) == ""
345+ }
0 commit comments