 ALTER TABLE device_command
     ADD COLUMN origin_session_id varchar(64);
 
-CREATE INDEX device_command_origin_session_id_idx ON device_command (origin_session_id);+--Indexes
+CREATE INDEX device_notification_timestamp_device_id_idx ON device_notification(timestamp, device_id);
+CREATE INDEX device_command_timestamp_device_id_idx ON device_command(timestamp, device_id);
+CREATE INDEX device_command_origin_session_id_idx ON device_command (origin_session_id);
+CREATE UNIQUE INDEX device_guid_idx ON device(guid);
+CREATE INDEX device_network_id_idx ON device(network_id);
+CREATE UNIQUE INDEX device_class_name_version_idx ON device_class(name, version);
+CREATE INDEX device_equipment_device_id_code_idx ON device_equipment(device_id, code);
+CREATE INDEX equipment_device_class_id_idx ON equipment(device_class_id);
+CREATE UNIQUE INDEX network_name_idx ON network(name);
+CREATE UNIQUE INDEX user_login_idx ON "user"(login);
+CREATE INDEX user_network_user_id_network_id_idx ON user_network(user_id, network_id);
+CREATE INDEX user_network_network_id_user_id_idx ON user_network(network_id, user_id);
+
+
+
+


ALTER TABLE oauth_client ADD CONSTRAINT oauth_client_pk PRIMARY KEY (id);
ALTER TABLE oauth_client ADD CONSTRAINT oauth_id_unique UNIQUE (oauth_id);
CREATE UNIQUE INDEX oauth_client_idx ON oauth_client (oauth_id);

CREATE TABLE oauth_grant (
  id BIGSERIAL NOT NULL,

ALTER TABLE access_key_permission ADD CONSTRAINT access_key_permission_pk PRIMARY KEY (id);
ALTER TABLE access_key_permission ADD CONSTRAINT access_key_permission_access_key_fk FOREIGN KEY (access_key_id) REFERENCES
access_key (id) ON DELETE CASCADE;
CREATE INDEX access_key_permission_access_key_id_idx ON access_key_permission(access_key_id);

CREATE TABLE oauth_client (
  id BIGSERIAL NOT NULL,
