-
Notifications
You must be signed in to change notification settings - Fork 346
-- atlas:import directive fails to resolve file paths containing spaces #3699
Description
Title
-- atlas:import directive fails to resolve file paths containing spaces
Body
Description
When using atlas schema inspect --format '{{ sql . | split | write "dir" }}' on a SQL Server database with object names containing spaces, Atlas generates filenames with spaces. The -- atlas:import directives in main.sql and individual SQL files then fail to resolve these paths because the parser splits on spaces.
Steps to Reproduce
-
Have a SQL Server database with objects whose names contain spaces (e.g.
[My Company$my table]) -
Export the schema:
atlas schema inspect \
-u "sqlserver://sa:pass@host:1433?database=mydb&encrypt=disable&mode=database" \
--format '{{ sql . | split | write "desired-state" }}'- Atlas generates files like:
desired-state/
├── main.sql
└── schemas/dbo/tables/
└── my company$my table.sql
main.sqlcontains:
-- atlas:import schemas/dbo/tables/my company$my table.sql- Try to use these files:
atlas schema diff \
--from "sqlserver://sa:pass@host:1433?database=mydb&encrypt=disable&mode=database" \
--to "file://desired-state/" \
--dev-url "sqlserver://sa:pass@host:1433?database=empty_db&encrypt=disable&mode=database"Expected Behavior
Atlas should resolve the full file path from the -- atlas:import directive, including spaces.
Actual Behavior
Error: desired-state/main.sql:3: stat desired-state/schemas/dbo/tables/my: no such file or directory
The parser truncates the path at the first space character (my instead of my company$my table.sql).
Same issue in cross-file imports
Individual SQL files also contain -- atlas:import directives with relative paths:
-- atlas:import ../../dbo/tables/my company$my table.sqlThese fail with the same error.
Workaround
Post-process the export to replace spaces with dashes in both filenames and -- atlas:import paths. This works but breaks the round-trip (re-exporting overwrites the fixes).
Environment
- Atlas version: v1.1.7-52a1d35-canary
- OS: macOS (Darwin 25.3.0)
- Database: SQL Server
Suggested Fix
Either:
- Quote or escape spaces in
-- atlas:importpaths (e.g.-- atlas:import "path with spaces.sql") - Parse the
-- atlas:importdirective to take the rest of the line as the path (not splitting on spaces) - Add a naming option to
split | writethat replaces spaces with dashes/underscores in generated filenames