Announcing v0.5.0 with Migration Directory Linting
With the release of v0.5.0, we are happy to announce a very significant milestone for the project. While this version includes some cool features (such as multi-file schemas) and a swath of incremental improvements and bugfixes, there is one feature that we're particularly excited about and want to share with you in this post.
As most outages happen directly as a result of a change to a system, Atlas provides users with the means to verify the
safety of planned changes before they happen. The sqlcheck
package provides interfaces for analyzing the contents of SQL files to generate insights on the safety of many kinds of
changes to database schemas. With this package, developers may define an Analyzer that can be used to diagnose the impact
of SQL statements on the target database.
This functionality is exposed to CLI users via the migrate lint subcommand. By utilizing
the sqlcheck package, Atlas can now check your migration directory for common problems
and issues.
atlas migrate lint in action
Recall that Atlas uses a dev database to plan and simulate schema changes. Let's start by spinning up a container that will serve as our dev database:
docker run --name atlas-db-dev -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=pass mysql
Next let's create schema.hcl, the HCL file which will contain the desired state of
our database:
schema "example" {
}
table "users" {
schema = schema.example
column "id" {
type = int
}
column "name" {
type = varchar(255)
}
primary_key {
columns = [
column.id
]
}
}
To simplify the commands we need to type in this demo, let's create an Atlas project file to define a local environment.
env "local" {
src = "./schema.hcl"
url = "mysql://root:pass@localhost:3306"
dev = "mysql://root:pass@localhost:3307"
}
Next, let's plan the initial migration that creates the users table:
atlas migrate diff --env local
Observe that the migrations/ directory was created with an .sql file and
a file named atlas.sum:
├── atlas.hcl
├── migrations
│ ├── 20220714090139.sql
│ └── atlas.sum