Inspecting existing schemas with Atlas
Automatic Schema Inspection
Many projects begin with an existing database that users wish to start managing with Atlas. In this case, instead of having developers learn the Atlas Language and reverse engineer a schema definition file that precisely describes the existing database, Atlas supports automatic schema inspection.
With automatic schema inspection, users simply provide Atlas with a connection string to their target database and Atlas prints out a schema definition file in the Atlas language that they can use as the starting point for working with this database.
Flags
When using schema inspect
to inspect an existing database, users may supply multiple
parameters:
--url
(required,-u
accepted as well) - the URL of database to be inspected.--schema
(optional, may be supplied multiple times) - schemas to inspect within the target database.--exclude
(optional, may be supplied multiple times) - filter out resources matching the given glob pattern.
Examples
Entire Database
- MySQL
- MariaDB
- PostgreSQL
- SQLite
atlas schema inspect -u "mysql://localhost"
atlas schema inspect -u "mysql://user:pass@localhost:3306"
atlas schema inspect -u "maria://localhost"
atlas schema inspect -u "maria://user:pass@localhost:3306"
atlas schema inspect -u "postgres://localhost:5432/database"
atlas schema inspect -u "postgres://postgres:pass@0.0.0.0:5432/database?sslmode=disable"
atlas schema inspect -u "sqlite://file.db"
atlas schema inspect -u "sqlite://file?cache=shared&mode=memory"
Single Schema
- MySQL
- MariaDB
- PostgreSQL
atlas schema inspect -u "mysql://localhost/schema"
atlas schema inspect -u "mysql://user:pass@localhost:3306/schema"
atlas schema inspect -u "maria://localhost/schema"
atlas schema inspect -u "maria://user:pass@localhost:3306/schema"
atlas schema inspect -u "postgres://localhost:5432/database?search_path=schema"
atlas schema inspect -u "postgres://postgres:pass@0.0.0.0:5432/database?sslmode=disable&sslmode=disable"
Multiple Schemas
- MySQL
- MariaDB
- PostgreSQL
atlas schema inspect -u "mysql://localhost" --schema schema1 --schema schema2
atlas schema inspect -u "mysql://user:pass@localhost:3306" -s schema1,schema2
atlas schema inspect -u "maria://localhost" --schema schema1 --schema schema2
atlas schema inspect -u "maria://user:pass@localhost:3306" -s schema1,schema2
atlas schema inspect -u "postgres://localhost:5432/database" --schema schema1 --schema schema2
atlas schema inspect -u "postgres://postgres:pass@0.0.0.0:5432/database?sslmode=disable" -s schema1,schema2
Exclude Schemas
atlas schema inspect -u "mysql://localhost" --exclude "internal"
atlas schema inspect -u "mysql://localhost" --exclude "schema_*"
Exclude Tables
atlas schema inspect -u "mysql://localhost" --exclude "*.prefix_*"
atlas schema inspect -u "mysql://localhost" --exclude "schema.table"
Exclude Table Resources
atlas schema inspect -u "mysql://localhost" --exclude "*.*.prefix_*"
atlas schema inspect -u "mysql://localhost" --exclude "public.*.c1"