Skip to content

Add SEQUENCE support (CREATE/ALTER/DROP)#83

Open
tomoemon wants to merge 1 commit intodaichirata:masterfrom
tomoemon:feature/support-sequence
Open

Add SEQUENCE support (CREATE/ALTER/DROP)#83
tomoemon wants to merge 1 commit intodaichirata:masterfrom
tomoemon:feature/support-sequence

Conversation

@tomoemon
Copy link
Copy Markdown

@tomoemon tomoemon commented Feb 19, 2026

If there is any reason not to support sequences, I would appreciate it if you could let me know.

Summary

  • Add support for Cloud Spanner CREATE SEQUENCE, ALTER SEQUENCE, DROP SEQUENCE statements
  • Sequences are created/altered before tables and dropped after tables to respect dependency ordering
  • Add --ignore-sequences flag to diff, apply, create, export commands

Tests

  • go test ./internal/hammer/... all pass
  • Manual test: go run . diff /dev/null db.sql correctly outputs SEQUENCE
  • Manual test: go run . diff spanner://... db.sql completes without error

🤖 Generated with Claude Code

Add support for Cloud Spanner SEQUENCE statements in diff, apply, create,
and export commands. Sequences are created before tables and dropped after
tables to respect dependency ordering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment on lines +1374 to +1380
// If params changed, we need DROP + CREATE
if !g.sequenceParamsEqual(from.Params, to.Params) {
ddl.Append(&ast.DropSequence{Name: from.Name})
ddl.Append(to.CreateSequence)
g.droppedSequence = append(g.droppedSequence, identsToComparable(from.Name.Idents...))
return ddl
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ast.SequenceParam can be translated into

DROP and CREATE sequence is not safe operation because sequences maintain their states. If it is needed, flag like --allow-recreate may be considerable choice. It is same as spanner-schema-diff-tool

By default, changes to indexes will also cause a failure. The
--allowRecreateIndexes command line option enables index changes by
generating statements to drop and recreate the index.

By default, changes to foreign key constraints will also cause a failure. The
--allowRecreateForeignKeys command line option enables foreign key changes by
generating statements to drop and recreate the constraint.

    --allowDropStatements         Enables output of DROP commands to delete
                                  columns, tables or indexes not used in the
                                  new DDL file.
    --allowRecreateForeignKeys    Allows dropping and recreating Foreign Keys
                                  (and their backing Indexes) to apply changes.
    --allowRecreateIndexes        Allows dropping and recreating secondary
                                  Indexes to apply changes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment. I agree with your point. I'll also check the specification of spanner-schema-diff-tool that you mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants