Write migrations with Diesel

This commit is contained in:
2024-09-20 00:07:01 +02:00
parent 2f297a3557
commit 18bd7ce3ab
6 changed files with 71 additions and 0 deletions

9
snow-scanner/diesel.toml Normal file
View File

@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
[migrations_directory]
dir = "/mnt/Dev/@wdes/security.wdes.eu/snow-scanner/migrations"

View File

@ -0,0 +1 @@
DROP TABLE `scanners`;

View File

@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS `scanners` (
ip VARCHAR(255) NOT NULL,
ip_type TINYINT(1) UNSIGNED NOT NULL,
scanner_name VARCHAR(255) NOT NULL,
ip_ptr VARCHAR(255) NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NULL,
last_seen_at DATETIME NULL,
last_checked_at DATETIME NULL,
PRIMARY KEY (ip, ip_type)
);

View File

@ -0,0 +1 @@
DROP TABLE `scan_tasks`;

View File

@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS `scan_tasks` (
task_group_id VARCHAR(255) NOT NULL,
cidr VARCHAR(255) NOT NULL,
created_by_username VARCHAR(255) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NULL,
started_at DATETIME NULL,
still_processing_at DATETIME NULL,
ended_at DATETIME NULL,
PRIMARY KEY (task_group_id, cidr)
);

View File

@ -0,0 +1,38 @@
// @generated automatically by Diesel CLI.
diesel::table! {
scan_tasks (task_group_id, cidr) {
#[max_length = 255]
task_group_id -> Varchar,
#[max_length = 255]
cidr -> Varchar,
#[max_length = 255]
created_by_username -> Varchar,
created_at -> Datetime,
updated_at -> Nullable<Datetime>,
started_at -> Nullable<Datetime>,
still_processing_at -> Nullable<Datetime>,
ended_at -> Nullable<Datetime>,
}
}
diesel::table! {
scanners (ip, ip_type) {
#[max_length = 255]
ip -> Varchar,
ip_type -> Unsigned<Tinyint>,
#[max_length = 255]
scanner_name -> Varchar,
#[max_length = 255]
ip_ptr -> Nullable<Varchar>,
created_at -> Datetime,
updated_at -> Nullable<Datetime>,
last_seen_at -> Nullable<Datetime>,
last_checked_at -> Nullable<Datetime>,
}
}
diesel::allow_tables_to_appear_in_same_query!(
scan_tasks,
scanners,
);