Announcing v0.22: Rename Detection, Table Locking Checks, and more
Hi everyone,
It's been a few weeks since our last release, and we're happy to be back with a version packed with brand new and exciting features. Here's what's inside:
RENAME
Detection - This version includes aRENAME
detector that identifies ambiguous situations of potential resource renames and interactively asks the user for feedback before generating the changes.- PostgreSQL Features
- UNIQUE and EXCLUDE - Unique constraints and exclusion constraints were added.
- Composite Types - Added support for composite types, which are user-defined types that represent the structure of a row.
- Table lock checks - Eight new checks that review migration plans and alert in cases of a potential table locks in different modes.
- SQL Server Sequence Support - Atlas now supports managing sequences in SQL Server.
Let's dive in!
RENAME
Detection
One of the first things we were asked when we introduced Atlas's declarative approach to schema management was,
“How are you going to deal with renames?” While column and table renames are a fairly rare event in the lifecycle of a project,
the question arises from the fact that it's impossible to completely disambiguate between RENAME
and DROP
and ADD
operations.
While the end schema will be the same in both cases, the actual impact of an undesired DROP
operation can be disastrous.
To avoid this, Atlas now detects potential RENAME
scenarios during the migration planning phase and prompts the user
about their intent.
Let's see this in action.
Assume we have a users
table with the column first_name
, which we changed to name
.
After running the atlas migrate diff
command to generate a migration, we will see the following:
? Did you rename "users" column from "first_name" to "name":
▸ Yes
No
If this was our intention, we will click "Yes" and the SQL statement will be a RENAME
statement.
If we click "No", the SQL statement will drop the first_name
column and create the name
column instead.
PostgreSQL Features
Unique and Exclude Constraints
Now, Atlas supports declaring unique and exclude constraints in your schema.
For example, if we were to add a unique constraint on a
name
column, it would look similar to:
# Columns only.
unique "name" {
columns = [column.name]
}
Read more about unique constraints in Atlas here.
Exclude constraints ensure that if any two rows are compared using a specified operator, at least one of the specified conditions must hold true. This means that the constraint ensures that no two rows satisfy the specified operator at the same time.
exclude "excl_speaker_during" {
type = GIST
on {
column = column.speaker
op = "="
}
on {
column = column.during
op = "&&"
}
}
Composite Types
Composite Types are user-defined data types that represent a structure of a row or record. Once defined, composite types can be used to declare columns in tables or used in functions and stored procedures.
For example, let's say we have a users
table where each user has an address
. We can create a composite type address
and add it as a column to the users
table:
composite "address" {
schema = schema.public
field "street" {
type = text
}
field "city" {
type = text
}
}
table "users" {
schema = schema.public
column "address" {
type = composite.address
}
}
schema "public" {
comment = "standard public schema"
}
Learn more about composite types here.