ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
5.9k stars 263 forks source link

Applying JSON schema results in errors #2298

Closed imiljkovic closed 11 months ago

imiljkovic commented 11 months ago

After generating JSON schema with the following command:

atlas schema inspect -u "sqlserver://sa:Pass123@localhost:1433?database=test"  --format '{{ json . }}' > schema.json

I tried applying it to the different database:

schema apply -u "sqlserver://sa:Pass123@localhost:1433?database=test2" --to file://schema.json --dev-url "sqlserver://sa:Sifra123%23@localhost:1433?database=test2"

resulting with:

Error: unknown schema file: "schema.json"

HCL schema works as expected.

I use the latest version (0.15.0) with SQL Server beta driver.

Is this a bug, or working with JSON is a one-way street? If so, are there any plans for adding full JSON support?

a8m commented 11 months ago

Hey @imiljkovic 👋

JSON is just one of the options for formatting the inspected schema, just like the{{ mermaid . }} option. There are no plans to support reading JSON schemas natively in Atlas as some basic features cannot be implemented with JSON.

However, you can write an external schema loader (data source) for it if you're interested. See this doc as an example: https://atlasgo.io/atlas-schema/external

Feel free to join our Discord server and message me if you need help with it.

folliehiyuki commented 11 months ago

Hi @a8m ! Can you give more details on which basic features of Atlas DDL that can't be expressed in JSON?

In my opinion, being able to have JSON schema input has these benefits:

For context, Terraform supports *.tf.json as input. This is used for the 2nd use case I list above, for example, in their terraform-cdk project.