Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- +micrate Up
-- SQL in section 'Up' is executed when this migration is applied

ALTER TABLE "asset"
ADD COLUMN name TEXT,
ADD COLUMN client_ids JSONB,
ADD COLUMN map_id TEXT,
ADD COLUMN bookable BOOLEAN DEFAULT TRUE,
ADD COLUMN accessible BOOLEAN DEFAULT FALSE,
ADD COLUMN zones TEXT[] DEFAULT '{}',
ADD COLUMN place_groups TEXT[] DEFAULT '{}',
ADD COLUMN assigned_to TEXT,
ADD COLUMN assigned_name TEXT,
ADD COLUMN features TEXT[] DEFAULT '{}',
ADD COLUMN images TEXT[] DEFAULT '{}',
ADD COLUMN notes TEXT,
ADD COLUMN security_system_groups TEXT[] DEFAULT '{}',
ADD COLUMN parent_id TEXT,
ADD CONSTRAINT fk_asset_parent
FOREIGN KEY (parent_id) REFERENCES asset(id) ON DELETE SET NULL;

CREATE INDEX IF NOT EXISTS idx_asset_map_id ON asset (map_id);
CREATE INDEX IF NOT EXISTS idx_asset_assigned_to ON asset (assigned_to);
CREATE INDEX IF NOT EXISTS idx_asset_assigned_name ON asset (assigned_name);
CREATE INDEX IF NOT EXISTS idx_asset_bookable ON asset (bookable);
CREATE INDEX IF NOT EXISTS idx_asset_accessible ON asset (accessible);
CREATE INDEX IF NOT EXISTS idx_asset_parent_id ON asset (parent_id);
CREATE INDEX IF NOT EXISTS idx_asset_client_ids ON asset USING gin (client_ids);
CREATE INDEX IF NOT EXISTS idx_asset_zones ON asset USING gin (zones);
CREATE INDEX IF NOT EXISTS idx_asset_place_groups ON asset USING gin (place_groups);
CREATE INDEX IF NOT EXISTS idx_asset_features ON asset USING gin (features);
CREATE INDEX IF NOT EXISTS idx_asset_images ON asset USING gin (images);
CREATE INDEX IF NOT EXISTS idx_asset_security_system_groups ON asset USING gin (security_system_groups);

ALTER TABLE "asset_category" ADD COLUMN IF NOT EXISTS hidden BOOLEAN DEFAULT FALSE;

-- +micrate Down
-- SQL section 'Down' is executed when this migration is rolled back
DROP INDEX IF EXISTS idx_asset_security_system_groups;
DROP INDEX IF EXISTS idx_asset_images;
DROP INDEX IF EXISTS idx_asset_features;
DROP INDEX IF EXISTS idx_asset_place_groups;
DROP INDEX IF EXISTS idx_asset_zones;
DROP INDEX IF EXISTS idx_asset_client_ids;
DROP INDEX IF EXISTS idx_asset_parent_id;
DROP INDEX IF EXISTS idx_asset_accessible;
DROP INDEX IF EXISTS idx_asset_bookable;
DROP INDEX IF EXISTS idx_asset_assigned_name;
DROP INDEX IF EXISTS idx_asset_assigned_to;
DROP INDEX IF EXISTS idx_asset_map_id;

ALTER TABLE asset
DROP CONSTRAINT fk_asset_parent,
DROP COLUMN parent_id,
DROP COLUMN security_system_groups,
DROP COLUMN notes,
DROP COLUMN images,
DROP COLUMN features,
DROP COLUMN assigned_name,
DROP COLUMN assigned_to,
DROP COLUMN place_groups,
DROP COLUMN zones,
DROP COLUMN accessible,
DROP COLUMN bookable,
DROP COLUMN map_id,
DROP COLUMN client_ids,
DROP COLUMN name;

ALTER TABLE "asset_category" DROP COLUMN hidden
18 changes: 18 additions & 0 deletions src/placeos-models/asset.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ module PlaceOS::Model
attribute other_data : JSON::Any?
attribute barcode : String?

attribute name : String?
attribute client_ids : JSON::Any? # {floorsense_id: "", other_id: ""} etc
attribute map_id : String?
attribute bookable : Bool = true
attribute accessible : Bool = false
attribute zones : Array(String) = [] of String, es_type: "keyword"
attribute place_groups : Array(String) = [] of String, es_type: "keyword"
attribute assigned_to : String? # email
attribute assigned_name : String? # name of user
# queryable with AND and OR operators
attribute features : Array(String) = [] of String, es_type: "keyword"
attribute images : Array(String) = [] of String, es_type: "keyword"
attribute notes : String? # email
attribute security_system_groups : Array(String) = [] of String, es_type: "keyword"

# attribute parent_id : String? # nested resource like lockers and locker banks
belongs_to Asset, foreign_key: "parent_id", association_name: "parent"

belongs_to AssetType, foreign_key: "asset_type_id", association_name: "asset_type"
belongs_to AssetPurchaseOrder, foreign_key: "purchase_order_id", association_name: "purchase_order"
belongs_to Zone, foreign_key: "zone_id", association_name: "zone"
Expand Down
1 change: 1 addition & 0 deletions src/placeos-models/asset_category.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module PlaceOS::Model
# i.e. a tablet
attribute name : String, es_subfield: "keyword"
attribute description : String?
attribute hidden : Bool = false

belongs_to AssetCategory, foreign_key: "parent_category_id", association_name: "parent_category"

Expand Down