Back to changelog
New
3 minute read

Snowflake: Sequence Support

Atlas now supports Snowflake sequences as first-class schema objects. Define them in HCL, and Atlas plans the right CREATE, ALTER, and DROP SEQUENCE statements. Tables, views, and tasks can declare sequence dependencies via depends_on.

Sequences in Snowflake generate unique, monotonically increasing (or decreasing) integer values, commonly used for surrogate keys and ordered ID columns. Atlas now manages sequences as first-class resources alongside your tables, views, and tasks.

Defining a Sequence

Use the sequence block to declare a sequence in your HCL schema. The schema attribute is required; start, increment, order, and comment are optional:

schema "sales" {}
sequence "customer_id_seq" {
schema = schema.sales
start = 1
increment = 1
comment = "Surrogate key for customer records"
}

Using a Sequence as a Column Default

A typical pattern is to assign the next sequence value as a column default so new rows get unique IDs automatically. Declare depends_on on the table so Atlas creates the sequence before the table during migration:

table "customers" {
schema = schema.sales
column "id" {
type = NUMBER
default = sql("customer_id_seq.NEXTVAL")
}
column "email" {
type = VARCHAR(255)
}
depends_on = [sequence.customer_id_seq]
}

Generated SQL

Atlas generates CREATE SEQUENCE, ALTER SEQUENCE, and DROP SEQUENCE statements based on the diff between your desired and current state:

-- Create sequence "customer_id_seq"
CREATE SEQUENCE "sales"."customer_id_seq"
START = 1
INCREMENT = 1
NOORDER
COMMENT = 'Surrogate key for customer records';

Changing increment or order is handled with ALTER SEQUENCE SET:

-- Increase batch size for bulk loads
ALTER SEQUENCE "sales"."customer_id_seq" SET INCREMENT = 100;
Important: Snowflake does not allow changing the start value of an existing sequence with ALTER SEQUENCE. When Atlas detects a change to start, it recreates the sequence with a DROP followed by a CREATE. This is useful when reseeding IDs after a data migration.
-- Changing start requires a recreate (Snowflake limitation)
DROP SEQUENCE "sales"."customer_id_seq";
CREATE SEQUENCE "sales"."customer_id_seq" START = 1000001 INCREMENT = 1 NOORDER;
featuresnowflakesequence