Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atlas migrate diff --env sqlalchemy doesn't work #18

Open
ericchansen opened this issue Sep 12, 2024 · 11 comments
Open

atlas migrate diff --env sqlalchemy doesn't work #18

ericchansen opened this issue Sep 12, 2024 · 11 comments
Assignees

Comments

@ericchansen
Copy link

This bug is reproducible without extra code.

(atlas) user@hostname:~/repos/atlas-provider-sqlalchemy/tests$ pip list
Package                           Version                           Editable project location
--------------------------------- --------------------------------- -----------------------------------------------------
atlas-provider-sqlalchemy         0.2.0                             /home/user/repos/atlas-provider-sqlalchemy
build                             1.2.2
CacheControl                      0.14.0
certifi                           2024.8.30
cffi                              1.17.1
charset-normalizer                3.3.2
cleo                              2.1.0
click                             8.1.7
crashtest                         0.4.1
cryptography                      43.0.1
distlib                           0.3.8
dulwich                           0.21.7
fastjsonschema                    2.20.0
filelock                          3.16.0
greenlet                          3.1.0
idna                              3.8
importlib_metadata                8.5.0
installer                         0.7.0
jaraco.classes                    3.4.0
jeepney                           0.8.0
keyring                           24.3.1
markdown-it-py                    3.0.0
mdurl                             0.1.2
more-itertools                    10.5.0
msgpack                           1.1.0
packaging                         24.1
pexpect                           4.9.0
pip                               22.0.2
pkginfo                           1.11.1
platformdirs                      4.3.2
poetry                            1.8.3
poetry-core                       1.9.0
poetry-plugin-export              1.8.0
ptyprocess                        0.7.0
pycparser                         2.22
Pygments                          2.18.0
pyproject_hooks                   1.1.0
rapidfuzz                         3.9.7
requests                          2.32.3
requests-toolbelt                 1.0.0
rich                              13.8.1
SecretStorage                     3.3.3
setuptools                        59.6.0
shellingham                       1.5.4
SQLAlchemy                        2.0.34
tomli                             2.0.1
tomlkit                           0.13.2
trove-classifiers                 2024.7.2
typer                             0.12.5
typing_extensions                 4.12.2
urllib3                           2.2.3
virtualenv                        20.26.4
zipp                              3.20.1
(atlas) user@hostname:~/repos/atlas-provider-sqlalchemy/tests$ python ../atlas_provider_sqlalchemy/main.py --dialect postgresql --path models
CREATE TABLE user_account (id SERIAL NOT NULL, name VARCHAR(30) NOT NULL, fullname VARCHAR(30), PRIMARY KEY (id));

CREATE TABLE address (id SERIAL NOT NULL, email_address VARCHAR(30) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY (id), FOREIGN KEY(user_id) REFERENCES user_account (id));

(atlas) user@hostname:~/repos/atlas-provider-sqlalchemy/tests$ atlas migrate diff --env sqlalchemy --config "file://atlas-script.hcl" --var dialect=postgresql
Error: exit status 1
@a8m
Copy link
Member

a8m commented Sep 14, 2024

Thanks for reporting this.

Atlas should also print the provider stdout when stderr contains unhelpful error like this: Error: exit status 1.

@a8m a8m self-assigned this Sep 14, 2024
@ronenlu
Copy link
Member

ronenlu commented Sep 15, 2024

@ericchansen How does your atlas-script.hcl file looks like?

@ericchansen
Copy link
Author

@ronenlu https://github.com/ariga/atlas-provider-sqlalchemy/blob/master/tests/atlas-script.hcl. Please refer to the command in my original issue for how the file is used.

@ronenlu
Copy link
Member

ronenlu commented Sep 22, 2024

@ericchansen I run the same commands after starting virtual env and got no error:

The migration directory is synced with the desired state, no changes to be made

What is the atlas version you are using?

@ericchansen
Copy link
Author

ericchansen commented Sep 26, 2024

$ atlas version
atlas community version v0.27.1-8cf2eee-canary
https://github.com/ariga/atlas/releases/latest
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

@rotemtam
Copy link
Member

Atlas community is very limited. I agree the error message needs to be better, can you try using the normal build of Atlas:

To install:

curl -sSf https://atlasgo.sh | sh

Further reading: Community vs Other Editions

@hhk7734
Copy link

hhk7734 commented Oct 16, 2024

data "external_schema" "sqlalchemy" {
  program = [
    "atlas-provider-sqlalchemy",
    "--path", "./app/infra/orm",
    "--dialect", "mysql"
  ]
}

the upper is my config.

I runed the below and got the error. try it :)

atlas-provider-sqlalchemy --path app/infra/orm --dialect mysql
InvalidRequestError: Class <class 'model.FrameworkDeployment'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class. in app/infra/orm/model.py
To skip on failed import, run: atlas-provider-sqlalchemy --skip-errors

@ronenlu
Copy link
Member

ronenlu commented Oct 22, 2024

@hhk7734 Did you run it from with in the virtual env?

@hhk7734
Copy link

hhk7734 commented Oct 22, 2024

@hhk7734 Did you run it from with in the virtual env?

@ronenlu
I ran it in poetry venv.

@ronenlu
Copy link
Member

ronenlu commented Oct 22, 2024

@hhk7734 how does your FrameworkDeployment model class definition looks like?

@hhk7734
Copy link

hhk7734 commented Oct 22, 2024

@ronenlu

class FrameworkDeployment(Base):
    __tablename__ = "frameworks"
    __table_args__ = (
        UniqueConstraint("zone", "version", name="uq_zone_version"),
        {"mysql_collate": "utf8mb4_general_ci"},
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
    requester: Mapped[str] = mapped_column(String(length=255))
    reason: Mapped[str] = mapped_column(String(length=255))

    # ...

    build_id: Mapped[int | None] = mapped_column(BigInteger)
    build_status: Mapped[schemas.Status] = mapped_column(default=schemas.Status.REQUESTED)
    build_requested_at: Mapped[datetime] = mapped_column(default=now)
    build_started_at: Mapped[datetime | None]
    build_succeeded_at: Mapped[datetime | None]

    deploy_id: Mapped[int | None] = mapped_column(BigInteger)
    deploy_status: Mapped[schemas.Status | None]
    deploy_requested_at: Mapped[datetime | None]
    deploy_started_at: Mapped[datetime | None]
    deploy_succeeded_at: Mapped[datetime | None]

    created_at: Mapped[datetime] = mapped_column(default=now)
    updated_at: Mapped[datetime] = mapped_column(default=now, onupdate=now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants