Skip to content

Commit

Permalink
Rewrite service install FKs on balena model
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
otaviojacobi committed Nov 28, 2024
1 parent e8576cd commit 96a9072
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 61 deletions.
76 changes: 29 additions & 47 deletions src/balena-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,10 @@ export interface Service {
>;
device__installs__service?: Array<ServiceInstall['Read']>;
service_install?: Array<ServiceInstall['Read']>;
device__installs__application__has__service_name__has__name?: Array<
device__has__application__has__service_name__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
service_install__has__name?: Array<
device__has__service__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device_service_environment_variable?: Array<
Expand Down Expand Up @@ -783,6 +777,15 @@ export interface Device {
device_environment_variable?: Array<DeviceEnvironmentVariable['Read']>;
device__has__config_var_name?: Array<DeviceConfigVariable['Read']>;
device_config_variable?: Array<DeviceConfigVariable['Read']>;
device__has__application__has__service_name__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__has__service__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device_service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__has__tag_key?: Array<DeviceTag['Read']>;
device_tag?: Array<DeviceTag['Read']>;
device__installs__image?: Array<ImageInstall['Read']>;
Expand All @@ -792,21 +795,6 @@ export interface Device {
>;
device__installs__service?: Array<ServiceInstall['Read']>;
service_install?: Array<ServiceInstall['Read']>;
device__installs__application__has__service_name__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
service_install__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device_service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
installs__image?: Array<ImageInstall['Read']>;
installs__application__has__service_name?: Array<ServiceInstall['Read']>;
installs__service?: Array<ServiceInstall['Read']>;
Expand Down Expand Up @@ -941,21 +929,6 @@ export interface ServiceInstall {
device: { __id: Device['Read']['id'] } | [Device['Read']];
installs__service: { __id: Service['Read']['id'] } | [Service['Read']];
id: Types['Serial']['Read'];
device__installs__application__has__service_name__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device__installs__service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
service_install__has__name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
device_service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
application__has__service_name:
| { __id: Service['Read']['id'] }
| [Service['Read']];
Expand All @@ -964,6 +937,15 @@ export interface ServiceInstall {
| { __id: Service['Read']['id'] }
| [Service['Read']];
is_installed_on__device: { __id: Device['Read']['id'] } | [Device['Read']];
is_of__device__has__application__has__service_name__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
is_of__device__has__service__has__env_var_name?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
is_of__device_service_environment_variable?: Array<
DeviceServiceEnvironmentVariable['Read']
>;
};
Write: {
created_at: Types['Date Time']['Write'];
Expand All @@ -978,14 +960,14 @@ export interface DeviceServiceEnvironmentVariable {
Read: {
created_at: Types['Date Time']['Read'];
modified_at: Types['Date Time']['Read'];
service_install:
| { __id: ServiceInstall['Read']['id'] }
| [ServiceInstall['Read']];
device: { __id: Device['Read']['id'] } | [Device['Read']];
service: { __id: Service['Read']['id'] } | [Service['Read']];
name: Types['Short Text']['Read'];
id: Types['Serial']['Read'];
value: Types['Text']['Read'];
service: { __id: Service['Read']['id'] } | [Service['Read']];
device: { __id: Device['Read']['id'] } | [Device['Read']];
service_install:
| { __id: ServiceInstall['Read']['id'] }
| [ServiceInstall['Read']];
device__installs__application__has__service_name:
| { __id: ServiceInstall['Read']['id'] }
| [ServiceInstall['Read']];
Expand All @@ -999,12 +981,12 @@ export interface DeviceServiceEnvironmentVariable {
Write: {
created_at: Types['Date Time']['Write'];
modified_at: Types['Date Time']['Write'];
service_install: ServiceInstall['Write']['id'];
device: Device['Write']['id'];
service: Service['Write']['id'];
name: Types['Short Text']['Write'];
id: Types['Serial']['Write'];
value: Types['Text']['Write'];
service: Service['Write']['id'];
device: Device['Write']['id'];
service_install: ServiceInstall['Write']['id'];
};
}

Expand Down Expand Up @@ -1329,7 +1311,7 @@ export default interface $Model {
device__has__config_var_name: DeviceConfigVariable;
device__installs__image: ImageInstall;
device__installs__application__has__service_name: ServiceInstall;
device__installs__application__has__service_name__has__name: DeviceServiceEnvironmentVariable;
device__has__application__has__service_name__has__env_var_name: DeviceServiceEnvironmentVariable;
device__has__tag_key: DeviceTag;
release: Release;
release__has__tag_key: ReleaseTag;
Expand Down
16 changes: 3 additions & 13 deletions src/balena.sbvr
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ Term: device
Term Form: service install
Database Table Name: service install

-- Target form for this table is:
-- Fact type: device has service has env var name
Fact type: service install has name (Auth)
Fact type: device has service has env var name
Term Form: device service environment variable
Database Table Name: device service environment variable

Expand Down Expand Up @@ -814,16 +812,8 @@ Fact type: image environment variable has value

Fact type: device service environment variable has value
Necessity: each device service environment variable has exactly one value.
Fact type: device service environment variable has service
-- This is the default name that will be given to the synonymous form
-- once the device service environment variable origin fact type changes
Synonymous form: service has device service environment variable
Necessity: each device service environment variable has exactly one service.
Fact type: device service environment variable has device
-- This is the default name that will be given to the synonymous form
-- once the device service environment variable origin fact type changes
Synonymous form: device has device service environment variable
Necessity: each device service environment variable has exactly one device.
Fact type: device service environment variable has service install
Necessity: each device service environment variable has exactly one service install.


-- application tag
Expand Down
8 changes: 8 additions & 0 deletions src/balena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
generateAbstractSqlModel,
renameVarResourcesName,
optimizeSchema,
renameField,
} from './abstract-sql-utils.js';

import * as userHasDirectAccessToApplication from './features/applications/models/user__has_direct_access_to__application.js';
Expand All @@ -22,6 +23,13 @@ export const model = {
abstractSql,
} satisfies ConfigLoader.Model;

renameField(
abstractSql,
'device-has-application-has-service name-has-env var name',
['has'],
'env var name',
'name',
);
renameVarResourcesName(abstractSql);

userHasDirectAccessToApplication.addToModel(abstractSql);
Expand Down
6 changes: 5 additions & 1 deletion src/translations/v7/v7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ overrideFieldType(v7AbstractSqlModel, 'release', 'version', 'JSON');
userHasDirectAccessToApplication.addToModel(v7AbstractSqlModel);
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- So that the interface is already well defined.
export const getV7Translations = (_abstractSqlModel = v7AbstractSqlModel) => {
return {} satisfies ConfigLoader.Model['translations'];
return {
'device-installs-application-has-service name-has-name': {
$toResource: 'device-has-application-has-service name-has-env var name',
},
} satisfies ConfigLoader.Model['translations'];
};

0 comments on commit 96a9072

Please sign in to comment.