Skip to content

-- atlas:import directive fails to resolve file paths containing spaces #3699

@TechnoWanderer42

Description

@TechnoWanderer42

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

  1. Have a SQL Server database with objects whose names contain spaces (e.g. [My Company$my table])

  2. Export the schema:

atlas schema inspect \
  -u "sqlserver://sa:pass@host:1433?database=mydb&encrypt=disable&mode=database" \
  --format '{{ sql . | split | write "desired-state" }}'
  1. Atlas generates files like:
desired-state/
├── main.sql
└── schemas/dbo/tables/
    └── my company$my table.sql
  1. main.sql contains:
-- atlas:import schemas/dbo/tables/my company$my table.sql
  1. 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.sql

These 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:

  1. Quote or escape spaces in -- atlas:import paths (e.g. -- atlas:import "path with spaces.sql")
  2. Parse the -- atlas:import directive to take the rest of the line as the path (not splitting on spaces)
  3. Add a naming option to split | write that replaces spaces with dashes/underscores in generated filenames

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions