First commit!
This commit is contained in:
30
db/migrate/20251102030111_create_network_ranges.rb
Normal file
30
db/migrate/20251102030111_create_network_ranges.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class CreateNetworkRanges < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :network_ranges do |t|
|
||||
t.binary :ip_address, null: false
|
||||
t.integer :network_prefix, null: false
|
||||
t.integer :ip_version, null: false
|
||||
t.string :company
|
||||
t.integer :asn
|
||||
t.string :asn_org
|
||||
t.boolean :is_datacenter, default: false
|
||||
t.boolean :is_proxy, default: false
|
||||
t.boolean :is_vpn, default: false
|
||||
t.string :ip_api_country
|
||||
t.string :geo2_country
|
||||
t.text :abuser_scores
|
||||
t.text :additional_data
|
||||
t.timestamp :last_api_fetch
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# Indexes for common queries
|
||||
add_index :network_ranges, [:ip_address, :network_prefix], name: 'idx_network_ranges_ip_range'
|
||||
add_index :network_ranges, :asn, name: 'idx_network_ranges_asn'
|
||||
add_index :network_ranges, :company, name: 'idx_network_ranges_company'
|
||||
add_index :network_ranges, :ip_api_country, name: 'idx_network_ranges_country'
|
||||
add_index :network_ranges, [:is_datacenter, :is_proxy, :is_vpn], name: 'idx_network_ranges_flags'
|
||||
add_index :network_ranges, :ip_version, name: 'idx_network_ranges_version'
|
||||
end
|
||||
end
|
||||
21
db/migrate/20251102044000_create_projects.rb
Normal file
21
db/migrate/20251102044000_create_projects.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class CreateProjects < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :projects do |t|
|
||||
t.string :name, null: false
|
||||
t.string :slug, null: false
|
||||
t.string :public_key, null: false
|
||||
t.boolean :enabled, default: true, null: false
|
||||
t.integer :rate_limit_threshold, default: 100, null: false
|
||||
t.integer :blocked_ip_count, default: 0, null: false
|
||||
t.text :custom_rules, default: "{}", null: false
|
||||
t.text :settings, default: "{}", null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :projects, :slug, unique: true
|
||||
add_index :projects, :public_key, unique: true
|
||||
add_index :projects, :enabled
|
||||
add_index :projects, :name
|
||||
end
|
||||
end
|
||||
37
db/migrate/20251102044052_create_events.rb
Normal file
37
db/migrate/20251102044052_create_events.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class CreateEvents < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :events do |t|
|
||||
t.references :project, null: false, foreign_key: true
|
||||
t.string :event_id, null: false
|
||||
t.datetime :timestamp, null: false
|
||||
t.string :action
|
||||
t.string :ip_address
|
||||
t.text :user_agent
|
||||
t.string :request_method
|
||||
t.string :request_path
|
||||
t.string :request_url
|
||||
t.string :request_protocol
|
||||
t.integer :response_status
|
||||
t.integer :response_time_ms
|
||||
t.string :rule_matched
|
||||
t.text :blocked_reason
|
||||
t.string :server_name
|
||||
t.string :environment
|
||||
t.string :country_code
|
||||
t.string :city
|
||||
t.string :agent_version
|
||||
t.string :agent_name
|
||||
t.json :payload
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :events, :event_id, unique: true
|
||||
add_index :events, :timestamp
|
||||
add_index :events, [:project_id, :timestamp]
|
||||
add_index :events, [:project_id, :action]
|
||||
add_index :events, [:project_id, :ip_address]
|
||||
add_index :events, :ip_address
|
||||
add_index :events, :action
|
||||
end
|
||||
end
|
||||
13
db/migrate/20251102080959_create_rule_sets.rb
Normal file
13
db/migrate/20251102080959_create_rule_sets.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateRuleSets < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :rule_sets do |t|
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.boolean :enabled
|
||||
t.json :projects
|
||||
t.json :rules
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
17
db/migrate/20251102081014_create_rules.rb
Normal file
17
db/migrate/20251102081014_create_rules.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class CreateRules < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
create_table :rules do |t|
|
||||
t.references :rule_set, null: false, foreign_key: true
|
||||
t.string :rule_type
|
||||
t.string :target
|
||||
t.string :action
|
||||
t.boolean :enabled
|
||||
t.datetime :expires_at
|
||||
t.integer :priority
|
||||
t.json :conditions
|
||||
t.json :metadata
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
11
db/migrate/20251102081043_add_fields_to_rule_sets.rb
Normal file
11
db/migrate/20251102081043_add_fields_to_rule_sets.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class AddFieldsToRuleSets < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_column :rule_sets, :slug, :string
|
||||
add_column :rule_sets, :priority, :integer
|
||||
add_column :rule_sets, :projects_subscription, :json
|
||||
|
||||
add_index :rule_sets, :slug, unique: true
|
||||
add_index :rule_sets, :enabled
|
||||
add_index :rule_sets, :priority
|
||||
end
|
||||
end
|
||||
15
db/migrate/20251102234055_add_simple_event_normalization.rb
Normal file
15
db/migrate/20251102234055_add_simple_event_normalization.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class AddSimpleEventNormalization < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
# Add foreign key for hosts (most valuable normalization)
|
||||
add_column :events, :request_host_id, :integer
|
||||
add_foreign_key :events, :request_hosts
|
||||
add_index :events, :request_host_id
|
||||
|
||||
# Add path segment storage as string for LIKE queries
|
||||
add_column :events, :request_segment_ids, :string
|
||||
add_index :events, :request_segment_ids
|
||||
|
||||
# Add composite index for common WAF queries using enums
|
||||
add_index :events, [:request_host_id, :request_method, :request_segment_ids], name: 'idx_events_host_method_path'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameActionToWafActionInEvents < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
rename_column :events, :action, :waf_action
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user