sparse-v2/sparse-server/migrations/20250223030447_better_commands.sql
2025-02-23 01:46:18 -05:00

50 lines
1.1 KiB
SQL

DROP TABLE beacon_command_invocation;
DROP TABLE beacon_command;
CREATE TABLE beacon_file (
file_id varchar PRIMARY KEY NOT NULL,
file_name varchar,
beacon_source_id varchar,
FOREIGN KEY (beacon_source_id) REFERENCES beacon_instance
);
CREATE TABLE beacon_command (
command_id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
cmd_type text check (cmd_type in ('update', 'exec', 'install', 'upload', 'download', 'chdir', 'ls')),
exec_command varchar,
install_target varchar,
upload_src varchar,
download_src varchar,
download_path varchar,
chdir_target varchar,
FOREIGN KEY (download_src) REFERENCES beacon_file
);
CREATE TABLE beacon_command_invocation (
beacon_id varchar NOT NULL,
command_id int NOT NULL,
issue_date int NOT NULL,
invoker_id int NOT NULL,
invocation_date int,
invocation_result varchar,
PRIMARY KEY (beacon_id, command_id),
FOREIGN KEY (command_id) REFERENCES beacon_command,
FOREIGN KEY (beacon_id) REFERENCES beacon_instance,
FOREIGN KEY (invoker_id) REFERENCES users
);