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

Prepare to migrate to sqlalchemy 2.0 #310

Closed
sde1000 opened this issue Jan 18, 2025 · 1 comment
Closed

Prepare to migrate to sqlalchemy 2.0 #310

sde1000 opened this issue Jan 18, 2025 · 1 comment

Comments

@sde1000
Copy link
Owner

sde1000 commented Jan 18, 2025

All the systems quicktill is installed on now have sqlalchemy 1.4, so it should be possible to start down the 1.x to 2.0 migration path.

See https://docs.sqlalchemy.org/en/20/changelog/migration_20.html

Deprecation warnings from the current (v23.14) state of quicktill:

steve@myrddin:~/quicktill$ SQLALCHEMY_WARN_20=1 python3 -W always::DeprecationWarning ./runtill -u file:examples/haymakers.py checkdb
/home/steve/quicktill/quicktill/models.py:100: MovedIn20Warning: The ``declarative_base()`` function is now available as sqlalchemy.orm.declarative_base(). (deprecated since: 1.4) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  Base = declarative_base(metadata=metadata, cls=Base)
/home/steve/quicktill/quicktill/models.py:622: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.sum(SessionTotal.amount)],
/home/steve/quicktill/quicktill/models.py:1394: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Transline.items * Transline.amount),
/home/steve/quicktill/quicktill/models.py:1404: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Transline.items * Transline.amount),
/home/steve/quicktill/quicktill/models.py:1415: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Transline.items * Transline.discount),
/home/steve/quicktill/quicktill/models.py:1428: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Transline.items * Transline.amount),
/home/steve/quicktill/quicktill/models.py:1437: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Transline.items * Transline.discount),
/home/steve/quicktill/quicktill/models.py:1446: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(
/home/steve/quicktill/quicktill/models.py:1456: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(Payment.amount), zero)],
/home/steve/quicktill/quicktill/models.py:2749: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([Delivery.checked])
/home/steve/quicktill/quicktill/models.py:2753: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([StockTake.commit_time != None])
/home/steve/quicktill/quicktill/models.py:2747: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([
/home/steve/quicktill/quicktill/models.py:2763: RemovedIn20Warning: The "whens" argument to case(), when referring to a sequence of items, is now passed as a series of positional elements, rather than as a list.  (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  case(
/home/steve/quicktill/quicktill/models.py:2762: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([
/home/steve/quicktill/quicktill/models.py:2874: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(StockOut.qty), text("0.0"))])
/home/steve/quicktill/quicktill/models.py:2883: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.coalesce(func.sum(StockOut.qty), text("0.0"))])
/home/steve/quicktill/quicktill/models.py:2893: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([StockItem.size
/home/steve/quicktill/quicktill/models.py:2902: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.min(StockOut.time)])
/home/steve/quicktill/quicktill/models.py:2911: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.max(StockOut.time)])
/home/steve/quicktill/quicktill/models.py:2930: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  StockItem.size - select(
/home/steve/quicktill/quicktill/models.py:2933: SADeprecationWarning: The SelectBase.as_scalar() method is deprecated and will be removed in a future release.  Please refer to SelectBase.scalar_subquery(). (deprecated since: 1.4)
  ).as_scalar()),
/home/steve/quicktill/quicktill/models.py:2927: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select(
/home/steve/quicktill/quicktill/models.py:2953: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  StockItem.size - select(
/home/steve/quicktill/quicktill/models.py:2956: SADeprecationWarning: The SelectBase.as_scalar() method is deprecated and will be removed in a future release.  Please refer to SelectBase.scalar_subquery(). (deprecated since: 1.4)
  ).as_scalar()),
/home/steve/quicktill/quicktill/models.py:2950: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select(
/home/steve/quicktill/quicktill/models.py:2967: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select([func.max(StockOut.time)],
/home/steve/quicktill/quicktill/models.py:3068: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0.  Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  select(
sde1000 added a commit that referenced this issue Jan 19, 2025
See #310 — sqlalchemy-2.0 migration
sde1000 added a commit that referenced this issue Jan 19, 2025
sde1000 added a commit that referenced this issue Jan 19, 2025
sde1000 added a commit that referenced this issue Jan 19, 2025
See #310 — sqlalchemy-2.0 migration
sde1000 added a commit that referenced this issue Jan 19, 2025
See #310 — sqlalchemy-2.0 migration
sde1000 added a commit that referenced this issue Jan 19, 2025
(Web interface not yet addressed.)

Remainder of td.s.query(model).get(pk) calls converted to td.s.get(model, pk)

Related object loader paths are no longer passed as strings
(joinedload(), undefer(), etc.)

select([things...], whereclause) converted to select(things...).where(cond)

See #310 on github.
sde1000 added a commit that referenced this issue Jan 21, 2025
Mostly the web interface.

See #310 on github.
sde1000 added a commit that referenced this issue Jan 24, 2025
sde1000 added a commit that referenced this issue Jan 24, 2025
Updates for sqlalchemy-2.0: MetaData.bind is no longer supported

Instead the engine is passed either explicitly when calling create_all()
etc. or implicitly as bound to the session.

See #310 on github.
sde1000 added a commit that referenced this issue Jan 24, 2025
sde1000 added a commit that referenced this issue Jan 24, 2025
The "slice index" feature of Query no longer accepts negative indices
in sqlalchemy-2.0.

See #310 on github.
sde1000 added a commit that referenced this issue Jan 24, 2025
Hopefully these are the last remaining query(model).get(key) calls,
and all have now been converted to session.get(model, key)

See #310 on github.
sde1000 added a commit that referenced this issue Jan 24, 2025
Hopefully the last remaining ones!

See #310 on github.
sde1000 added a commit that referenced this issue Jan 24, 2025
Removed in sqlalchemy-2.0 - use .join(x).join(y)... instead

See #310 on github.
sde1000 added a commit that referenced this issue Jan 25, 2025
See #310 — sqlalchemy-2.0 migration
sde1000 added a commit that referenced this issue Jan 25, 2025
sde1000 added a commit that referenced this issue Jan 25, 2025
Generally:

td.s.query(model).get(pk) -> td.s.get(model, pk)

.join(a, b, c) -> .join(a).join(b).join(c)

Don't pass strings to .joinedload(), .undefer(), etc.

select([a, b], whereclause=cond) converted to select(a, b).where(cond)

See #310 — sqlalchemy-2.0 migration
sde1000 added a commit that referenced this issue Jan 25, 2025
sde1000 added a commit that referenced this issue Jan 25, 2025
The "slice index" feature of Query no longer accepts negative indices
in sqlalchemy-2.0.

See #310 on github.
sde1000 added a commit that referenced this issue Jan 25, 2025
Updates for sqlalchemy-2.0: MetaData.bind is no longer supported

Instead the engine is passed either explicitly when calling create_all()
etc. or implicitly as bound to the session.

See #310 on github.
sde1000 added a commit that referenced this issue Jan 25, 2025
@sde1000
Copy link
Owner Author

sde1000 commented Jan 25, 2025

I believe this is now complete — the till should run correctly with sqlalchemy-1.4 with future=True set on the ORM session, and with sqlalchemy-2.0; the web interface should run with sqlalchemy-1.4 with future=False or future=True, or with sqlalchemy-2.0

@sde1000 sde1000 closed this as completed Jan 25, 2025
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

1 participant