Commit graph

45 commits

Author SHA1 Message Date
d872835093
New API to check if a table class exists before defining it.
- Check if it's part of the metadata through a function call rather than
  checking `Base.metadata` in every single module.

- Make it possible to override them (mostly for doc generation logic
  that needs to be able to import those classes).

- Make it possible to extend them.
2023-10-09 01:33:44 +02:00
c311987741
Removed typing.Final from some of the most commonly used modules.
`typing.Final` is not defined on Python < 3.8.
2023-09-26 23:50:10 +02:00
a8255f3621
Pass the configuration file used by the application to the Alembic process.
The database settings could also be overridden in the configuration file
besides the command line.

We should therefore pass the path to the runtime configuration file, so
the Alembic process can initialize its configuration from the same file
and use the same settings.
2023-08-19 13:23:20 +02:00
181da63c89
Pass the database engine to the Alembic process as an extra argument.
If the path of the default database engine is overridden via `--workdir`
option then it won't be visible to the new `python` subprocess spawned
for Alembic.
2023-08-19 13:02:05 +02:00
2cab836bdf
Entity.columns class property replaced by Entity.get_columns method.
Again, Python < 3.9 doesn't like the combination of `@property` +
`@classmethod`.
2023-08-18 17:20:53 +02:00
998990aabc
Made Entity.children_ids resilient against deleted objects. 2023-05-01 22:09:16 +02:00
ce248ccfbb
Added children_ids to the entity attributes serialized in to_json. 2023-05-01 19:59:13 +02:00
78cee5d9b0
Added support for automatic database migrations.
Added Alembic environment and `run_db_migrations` logic to the entities
engine so database schema changes can be processed as soon as the
application is started.
2023-04-29 11:32:31 +02:00
8478245cde
Removed Mapped[Entity] type annotation.
`Mapped` has been introduced only in SQLAlchemy 1.4, while Debian stable
still ships 1.3.

Removing the type annotation doesn't come with a big cost, but it keeps
Platypush compatible with Debian stable.
2023-04-24 21:48:52 +02:00
4c19535612 A more resilient logic on entity copy/serialization to prevent ObjectDeletedError 2023-04-13 17:16:21 +02:00
3cd42c9e45
Entity should use Message.Encoder as a JSON serializer. 2023-04-02 02:44:19 +02:00
9e5ad0e0b1
Entity.to_dict now takes into account columns mapped to properties.
No more `_value` in the JSON output instead of the `value` property.

If a column is marked as private, and there's an associated property
mapped to its public name, then we should use and serialize that value.
2023-04-02 02:22:40 +02:00
b1cb7ef847
Added a list of excluded_manufacturers to BluetoothPlugin. 2023-03-21 14:32:45 +01:00
878fe91155
Big rewrite/refactor of the entities merger 2023-03-19 12:40:48 +01:00
4bc61133c5
The Entity object should also have a to_json method. 2023-03-12 23:01:51 +01:00
f45e47363d
Use lazy='joined' instead of lazy='selectin' on Entity.parent.
That's the best way to ensure that all the columns are fetched eagerly and
prevent errors later when trying to access lazily loaded attributes outside
of the session/thread.
2023-03-10 12:01:23 +01:00
7e92d5f244
Added recursive .copy() method to Entity. 2023-03-09 22:35:31 +01:00
9f9ee575f1
Added _import_error_ignored_modules.
ImportErrors on these entity modules will be ignored when dynamically
loading them, since they have optional external dependencies and we
shouldn't throw an error if we can't import them.
2023-03-09 01:40:35 +01:00
c4efec6832
Several fixes and improvements on the entities engine.
- Support for an optional callback on `publish_entities` to get notified
  when the published object are flushed to the db.

- Use `lazy='selectin'` for the entity parent -> children relationship -
  it is more efficient and it ensures that all the data the application
  needs is loaded upfront.

- `Entity.entity_key` rolled back to `<external_id, plugin>`. The
  fallback logic on `<id, plugin>` created more problems than those it
  as supposed to solve.

- Added `expire_on_commit=False` to the entities engine session to make
  sure that we don't get errors on detached/expired instances.
2023-03-09 01:16:04 +01:00
1781a19a79
s/Entity.to_json/Entity.to_dict/g
stuff
2023-03-06 23:46:33 +01:00
b9efa9fa30
entity_key should coalesce (entity.external_id or entity.id) 2023-03-06 16:54:02 +01:00
9a5e2899e8
Support for external_url and image_url on entities 2023-01-15 20:01:47 +01:00
c32aecece3
Added is_configuration flag to entities 2023-01-03 23:12:27 +01:00
1c811a490f
Don't serialize children_ids in Entity.to_json()
Serializing both children_ids and parent_id can result in nasty
SQLAlchemy bugs, especially when handling objects that haven't been
flushed yet.
2023-01-01 12:47:15 +01:00
2feaba7bf4
Add children_ids attribute to entities when converted to JSON 2022-12-18 21:03:12 +01:00
b0464219d3
Large refactor of the entities engine. 2022-12-17 21:41:23 +01:00
0edd73690b
Modelling of parent/children relationships on entity level 2022-11-28 21:36:00 +01:00
86edd70d93
Fixed session/concurrency management on the main SQLite db
- The `declarative_base` instance should be shared
- Database `session_locks` should be stored at module, not instance
  level
- Better isolation of scoped sessions
- Enclapsulated `get_session` method in `UserManager`
2022-11-12 15:36:17 +01:00
6b7933cd33
Using a different SQLite database for entities
This prevents multiprocessing/concurrency issues when modifying the same
database file both from the main process and from the web server process
2022-11-12 02:00:55 +01:00
02a4c9f667
Added is_query_disabled attribute to entities 2022-11-11 20:40:36 +01:00
041f64c80f
Dirty workaround to prevent redefinition of SQLAlchemy ORM model classes 2022-10-10 01:38:15 +02:00
5f09d449f4
extend_existing=True for entity tables 2022-10-09 23:15:50 +02:00
6ec8a991df
Fixed tests 2022-10-08 15:18:26 +02:00
1df71cb54a
Proper support for light entities on smartthings 2022-05-30 09:23:05 +02:00
7df67aca82
updated_at should have utcnow() onupdate, not now() 2022-04-30 01:48:55 +02:00
47f8520f3b
Added support for description/read_only/write_only on entity level 2022-04-24 22:18:29 +02:00
f52b556219
- icon_class should not be part of the backend model
- Interaction with entities should occur through the `entities.action`
  method, not by implementing native methods on each of the model
  objects
2022-04-08 16:49:47 +02:00
947b50b937
Added meta as a JSON field on the Entity table
Metadata attributes can now be defined and overridden on the object
itself, as well as on the database. Note that db settings will always
take priority in case of value conflicts.
2022-04-07 22:11:31 +02:00
db7c2095ea
Implemented meta property for entities (for now it only include icon_class) 2022-04-07 18:09:25 +02:00
44707731a8
Normalize UTC timezone on all the entity timestamps 2022-04-07 01:13:29 +02:00
2eeb1d4fea
Entity objects are now JSON-able 2022-04-07 00:21:54 +02:00
061268cdaf
Support for direct actions on native entities [WIP] 2022-04-05 23:22:54 +02:00
fe0f3202fe
columns should be a property of the Entity object 2022-04-05 23:04:19 +02:00
8a70f1d38e
Replaced deprecated sqlalchemy.ext.declarative with sqlalchemy.orm 2022-04-05 22:47:44 +02:00
4ee7e4db29
Basic support for entities on the local db and implemented support for switch entities on the tplink plugin 2022-04-04 16:50:17 +02:00