placeos-models

Version, currently 9.113.0116 versions

github.com/PlaceOS/models

PlaceOS entity models.

2 stars
0 dependents
License: NOASSERTION

Nothing has been indexed for 9.113.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  placeos-models:
    github: PlaceOS/models
    version: ~> 9.113.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 9.113.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

PlaceOS Models

CI Documentation Changelog

The database models for PlaceOS in crystal.

PlaceOS is a distributed application, with many concurrent event sources that require persistence. We use RethinkDB to unify our database and event bus, giving us a consistent interface to state and events across the system.

Configuration

Environment

KeyDescriptionDefault
PLACE_MAX_VERSIONSNumber of versions to keep of versioned models20
PG_HOSTPostgresql host"localhost"
PG_PORTPostgresql port5432
PG_DBDatabase name or PG_DATABASE"test"
PG_USERDatabase user"postgres"
PG_PASSWORDDatabase password""
PG_QUERYQuery string, that can be used to configure pooling""
PG_LOCK_TIMEOUTTimeout on retrying Advisory lock in seconds5
PG_DATABASE_URLOr provide a Database DSN

Runtime changefeed notifications

These models declare the fields that can change without notifying running services:

ModelIgnored update columns
Moduleupdated_at, has_runtime_error, error_timestamp
Drivername, description, update_available, update_info, compilation_output, updated_at, search_vector
Zonename, description, display_name, playlists, images, updated_at, search_vector
ControlSystemsignage_last_seen, playlist_item_id, name, description, version, updated_at, playlists, orientation, search_vector

The SQL trigger skips CDC rows and notifications when an update changes only ignored fields; the values still persist. Automatic updated_at and generated search_vector changes are included so ordinary metadata saves stay silent. Changes to other columns still notify, even when the same write changes ignored fields. Inserts and deletes are unchanged. Driver saves also skip saving associated modules whose copied name and role already match, preventing redundant module events; Driver.module_name and role changes still synchronize associated modules and emit their events. Driver.module_name, Module.name and ControlSystem.display_name are not ignored. Setting or clearing ControlSystem display_name emits an update.

Policies apply to every writer once the model's changefeed is registered. No-op updates on these tables are also silent. Consumers that need current metadata or signage configuration should read PostgreSQL rather than rely on these changefeeds. created_at and other unlisted fields remain notification-producing.

Deploy EventBus 1.1.0 or newer to every service that installs CDC triggers before enabling filtering. Older installers can restore the combined trigger and produce unwanted or duplicate events. pg-orm 2.4.1 or newer passes the model declaration, including explicit database-only columns, to EventBus; no core-side filter is required.

Module, Driver and Zone acquire their policies on first registration without a schema migration. For an existing ControlSystem policy, coordinate upgrading its subscribers and explicitly replace the installed policy before they register the new declaration. Old declarations conflict with the new policy, so avoid overlapping registration by the two versions. With the current models loaded, upgrade from the previous ten-column policy using:

EventBus.new(ENV["PG_DATABASE_URL"]).replace_cdc_update_policy(
  "sys",
  ignore_update_columns: PlaceOS::Model::ControlSystem.changefeed_ignored_update_columns.not_nil!,
  expected_ignore_update_columns: ["signage_last_seen", "playlist_item_id", "name", "description", "display_name", "version", "updated_at", "playlists", "orientation", "search_vector"]
)

For the earlier eight-column policy, omit playlists and orientation from the expected list. If only the original two-column policy was installed, use ["signage_last_seen", "playlist_item_id"] as the expected list instead. Fresh installations need no replacement. Do not guess the installed policy or suppress a mismatch error. For rollback, use replace_cdc_update_policy with the expected current columns; merely removing a declaration preserves the installed policy.

Testing

# prune docker images if you have new migrations that need to run
# since the last time migrations image was built
docker system prune --all

# builds migrations and runs tests in a containerised env
./test

Contributing

See CONTRIBUTING.md.