Browse Source

Merge database migration files

pull/3/head
Lukas Matt 11 months ago
parent
commit
79f35ed052
56 changed files with 448 additions and 440 deletions
  1. +19
    -0
      README.md
  2. +0
    -4
      db/migrations/000001_init.down.sql
  3. +0
    -14
      db/migrations/000001_init.up.sql
  4. +0
    -1
      db/migrations/000002_add_column_destination_net_bios_to_connections.down.sql
  5. +0
    -1
      db/migrations/000002_add_column_destination_net_bios_to_connections.up.sql
  6. +0
    -1
      db/migrations/000003_add_table_connection_infos.down.sql
  7. +0
    -28
      db/migrations/000003_add_table_connection_infos.up.sql
  8. +0
    -4
      db/migrations/000004_add_geoip_columns_to_connection_infos.down.sql
  9. +0
    -4
      db/migrations/000004_add_geoip_columns_to_connection_infos.up.sql
  10. +0
    -1
      db/migrations/000005_add_mac_column_to_connection_infos.up.sql
  11. +0
    -9
      db/migrations/000006_add_pi_class_column_to_connection_infos.up.sql
  12. +0
    -24
      db/migrations/000007_rename_connection_info.up.sql
  13. +0
    -50
      db/migrations/000008_create_profiling_tables.up.sql
  14. +0
    -1
      db/migrations/000009_drop_column_updated_at_from_ip_profiles.up.sql
  15. +0
    -7
      db/migrations/000010_create_mac_profile_table.up.sql
  16. +0
    -1
      db/migrations/000011_create_mac_profile_table.up.sql
  17. +0
    -2
      db/migrations/000012_drop_column_created_at_from_profile_tables.up.sql
  18. +0
    -1
      db/migrations/000013_drop_table_mac_profiles.up.sql
  19. +0
    -4
      db/migrations/000014_add_column_report_date_to_ip_profile_table.up.sql
  20. +0
    -12
      db/migrations/000015_create_alerting_table.up.sql
  21. +0
    -28
      db/migrations/000016_update_alerting_table.up.sql
  22. +0
    -6
      db/migrations/000017_create_statistic_table.up.sql
  23. +0
    -12
      db/migrations/000018_create_exception_table.up.sql
  24. +0
    -1
      db/migrations/000019_connections_drop_column_state.up.sql
  25. +0
    -6
      db/migrations/000020_change_alert_and_exception_type_numbers.up.sql
  26. +0
    -11
      db/migrations/000021_create_profile_table.up.sql
  27. +0
    -9
      db/migrations/000022_alter_profile_table_add_constraint.up.sql
  28. +0
    -11
      db/migrations/000023_alter_profile_table_add_columns.up.sql
  29. +0
    -18
      db/migrations/000024_fix_mlc.up.sql
  30. +0
    -8
      db/migrations/000025_create_configuration_table.up.sql
  31. +0
    -7
      db/migrations/000026_modify_notifications.up.sql
  32. +0
    -15
      db/migrations/000027_create_user_table.up.sql
  33. +0
    -10
      db/migrations/000028_create_bearer_token_table.up.sql
  34. +0
    -12
      db/migrations/000029_create_portal_event_table.up.sql
  35. +0
    -5
      db/migrations/000030_alter_portal_event_table.up.sql
  36. +0
    -3
      db/migrations/000031_alter_portal_event_table.up.sql
  37. +0
    -1
      db/migrations/000032_alter_portal_event_table.up.sql
  38. +0
    -1
      db/migrations/000033_alter_portal_event_table.up.sql
  39. +0
    -3
      db/migrations/000034_alter_portal_event_table.up.sql
  40. +0
    -5
      db/migrations/000035_create_portal_migrations_table.up.sql
  41. +0
    -3
      db/migrations/000036_alter_portal_migrations_table.up.sql
  42. +0
    -33
      db/migrations/000037_create_pattern_table.up.sql
  43. +0
    -2
      db/migrations/000038_alter_pattern_table.up.sql
  44. +0
    -2
      db/migrations/000039_alter_pattern_table.up.sql
  45. +0
    -5
      db/migrations/000040_create_pattern_category_lists_table.up.sql
  46. +0
    -15
      db/migrations/000041_alter_pattern_category_lists_table.up.sql
  47. +0
    -1
      db/migrations/000042_alter_pattern_categories_table.up.sql
  48. +0
    -21
      db/migrations/000043_create_network_interface_table.up.sql
  49. +0
    -2
      db/migrations/000044_alter_networks_table.up.sql
  50. +0
    -8
      db/migrations/000045_alter_networks_table.up.sql
  51. +0
    -1
      db/migrations/000046_alter_networks_table.up.sql
  52. +0
    -1
      db/migrations/000047_alter_network_interfaces_table.up.sql
  53. +0
    -3
      db/migrations/000048_alter_network_interfaces_table.up.sql
  54. +0
    -1
      db/migrations/000049_alter_network_interfaces_table.up.sql
  55. +0
    -1
      db/migrations/000050_alter_network_interfaces_table.up.sql
  56. +429
    -0
      db/migrations/000050_merged_initial_database.up.sql

+ 19
- 0
README.md View File

@@ -46,3 +46,22 @@ go build \
-asmflags=all=-trimpath=$(pwd) \
-ldflags "-X tea.fen.gg/fengg/server/config.VERSION=$VERSION"
```

### Merge database migration files

Drop the database and create a new one. Afterwards remember the highest
schema version and delete all files in `db/migrations`.

Then run the following command (replace XXX with the mentioned version):

``` bash
pg_dump \
-T public.schema_migrations \
-O -s -U postgres -d fengg \
| sed -e '/^--/d' \
| sed -e '/^$/d' \
| grep -v '^SELECT pg_catalog\.set_config.*search_path' \
> db/migrations/000XXX_merged_initial_database.up.sql
```

Commit and test your changes!

+ 0
- 4
db/migrations/000001_init.down.sql View File

@@ -1,4 +0,0 @@
drop index connections_index_on_source_ip_and_destination_ip_and_protocol;
drop index connections_index_on_destination_ip;

drop table connections;

+ 0
- 14
db/migrations/000001_init.up.sql View File

@@ -1,14 +0,0 @@
create table connections (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
protocol int not null,
source_ip text not null,
destination_ip text not null,
destination_reverse_dns text not null,
state int not null default 0,
count int default 1
);

create unique index connections_index_on_source_ip_and_destination_ip_and_protocol on connections (source_ip, destination_ip, protocol);
create index connections_index_on_destination_ip on connections (destination_ip);

+ 0
- 1
db/migrations/000002_add_column_destination_net_bios_to_connections.down.sql View File

@@ -1 +0,0 @@
alter table connections drop column destination_net_bios;

+ 0
- 1
db/migrations/000002_add_column_destination_net_bios_to_connections.up.sql View File

@@ -1 +0,0 @@
alter table connections add column destination_net_bios text;

+ 0
- 1
db/migrations/000003_add_table_connection_infos.down.sql View File

@@ -1 +0,0 @@
raise exception 'cannot rollback 000003_add_table_connection_infos';

+ 0
- 28
db/migrations/000003_add_table_connection_infos.up.sql View File

@@ -1,28 +0,0 @@
create table connection_infos (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
ip text not null,
reverse_dns text not null default '',
net_bios text not null default ''
);

create unique index connection_infos_index_on_ip on connection_infos (ip);

alter table connections add column destination_id int default 0;
alter table connections add column source_id int default 0;

insert into connection_infos(created_at, updated_at, ip, reverse_dns, net_bios)
select now(), now(), destination_ip, string_agg(destination_reverse_dns, ','), string_agg(destination_net_bios, ',')
from connections group by destination_ip on conflict (ip) do nothing;

insert into connection_infos(created_at, updated_at, ip)
select now(), now(), source_ip from connections group by source_ip on conflict (ip) do nothing;

update connections set destination_id=i.id from connection_infos as i where destination_ip=i.ip;
update connections set source_id=i.id from connection_infos as i where source_ip=i.ip;

alter table connections drop column destination_net_bios;
alter table connections drop column destination_reverse_dns;
alter table connections drop column destination_ip;
alter table connections drop column source_ip;

+ 0
- 4
db/migrations/000004_add_geoip_columns_to_connection_infos.down.sql View File

@@ -1,4 +0,0 @@
alter table connection_infos drop column country;
alter table connection_infos drop column european_union;
alter table connection_infos drop column anonymous_proxy;
alter table connection_infos drop column satellite_provider;

+ 0
- 4
db/migrations/000004_add_geoip_columns_to_connection_infos.up.sql View File

@@ -1,4 +0,0 @@
alter table connection_infos add column country text not null default '';
alter table connection_infos add column european_union boolean not null default false;
alter table connection_infos add column anonymous_proxy boolean not null default false;
alter table connection_infos add column satellite_provider boolean not null default false;

+ 0
- 1
db/migrations/000005_add_mac_column_to_connection_infos.up.sql View File

@@ -1 +0,0 @@
ALTER TABLE public.connection_infos ADD COLUMN mac text;

+ 0
- 9
db/migrations/000006_add_pi_class_column_to_connection_infos.up.sql View File

@@ -1,9 +0,0 @@
ALTER TABLE public.connections ADD COLUMN application_protocol text NOT NULL DEFAULT 'UNKNOWN';
CREATE UNIQUE INDEX connections_unique_index_on_protocol_columns_dst_id_and_src_id ON public.connections
USING btree
(
protocol,
application_protocol,
destination_id,
source_id
);

+ 0
- 24
db/migrations/000007_rename_connection_info.up.sql View File

@@ -1,24 +0,0 @@
SET search_path=public,pg_catalog;
DROP INDEX IF EXISTS public.connections_unique_index_on_protocol_columns_dst_id_and_src_id CASCADE;
DROP INDEX IF EXISTS public.connection_infos_index_on_ip CASCADE;
DROP TABLE IF EXISTS public.connection_infos CASCADE;
ALTER TABLE public.connections DROP COLUMN IF EXISTS protocol CASCADE;
ALTER TABLE public.connections DROP COLUMN IF EXISTS count CASCADE;
ALTER TABLE public.connections ADD COLUMN transport_protocol integer NOT NULL;
ALTER TABLE public.connections ADD COLUMN daily_count integer NOT NULL DEFAULT 1;
CREATE TABLE public.ip_information (
id serial primary key,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
ip text NOT NULL,
reverse_dns text NOT NULL DEFAULT '',
net_bios text NOT NULL DEFAULT '',
country text NOT NULL DEFAULT '',
european_union boolean NOT NULL DEFAULT false,
anonymous_proxy boolean NOT NULL DEFAULT false,
satellite_provider boolean NOT NULL DEFAULT false,
mac text NOT NULL
);
CREATE UNIQUE INDEX connection_infos_index_on_ip ON public.ip_information(ip);
ALTER TABLE public.connections ALTER COLUMN destination_id SET NOT NULL;
ALTER TABLE public.connections ALTER COLUMN source_id SET NOT NULL;

+ 0
- 50
db/migrations/000008_create_profiling_tables.up.sql View File

@@ -1,50 +0,0 @@
create table protocols (
id serial primary key,
created_at timestamp not null,
name text not null
);
create unique index protocols_index_on_name on protocols(name);

create table ip_profiles (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
ip_information_id int references ip_information(id),
protocol_id int references protocols(id),
weight real not null default 0
);
create unique index ip_profiles_index_on_name on ip_profiles(ip_information_id, protocol_id);

insert into protocols(created_at, name) select distinct now(), application_protocol from connections;

insert into protocols(created_at, name) values(now(), 'ICMPv4') ON CONFLICT DO NOTHING;
insert into protocols(created_at, name) values(now(), 'IGMP') ON CONFLICT DO NOTHING;
insert into protocols(created_at, name) values(now(), 'TCP') ON CONFLICT DO NOTHING;
insert into protocols(created_at, name) values(now(), 'UDP') ON CONFLICT DO NOTHING;

alter table connections add column application_protocol_id int;
alter table connections add column transport_protocol_id int;

update connections
set application_protocol_id=sub.id
from (select id, name from protocols) as sub
where application_protocol = sub.name;

update connections set transport_protocol_id=sub.id
from (select id from protocols where name = 'ICMPv4') as sub
where transport_protocol = 1;
update connections set transport_protocol_id=sub.id
from (select id from protocols where name = 'IGMP') as sub
where transport_protocol = 2;
update connections set transport_protocol_id=sub.id
from (select id from protocols where name = 'TCP') as sub
where transport_protocol = 6;
update connections set transport_protocol_id=sub.id
from (select id from protocols where name = 'UDP') as sub
where transport_protocol = 17;

alter table connections add constraint connections_transport_protocol_id_fk foreign key (transport_protocol_id) references protocols(id);
alter table connections add constraint connections_application_protocol_id_fk foreign key (application_protocol_id) references protocols(id);

alter table connections drop column application_protocol;
alter table connections drop column transport_protocol;

+ 0
- 1
db/migrations/000009_drop_column_updated_at_from_ip_profiles.up.sql View File

@@ -1 +0,0 @@
alter table ip_profiles drop column updated_at;

+ 0
- 7
db/migrations/000010_create_mac_profile_table.up.sql View File

@@ -1,7 +0,0 @@
create table mac_profiles (
id serial primary key,
created_at timestamp not null,
ip_information_id int references ip_information(id),
weight real not null default 0
);
create unique index mac_profiles_index_on_ip_information_id on mac_profiles(ip_information_id);

+ 0
- 1
db/migrations/000011_create_mac_profile_table.up.sql View File

@@ -1 +0,0 @@
alter table connections add column archived boolean not null default false;

+ 0
- 2
db/migrations/000012_drop_column_created_at_from_profile_tables.up.sql View File

@@ -1,2 +0,0 @@
alter table ip_profiles drop column created_at;
alter table mac_profiles drop column created_at;

+ 0
- 1
db/migrations/000013_drop_table_mac_profiles.up.sql View File

@@ -1 +0,0 @@
drop table mac_profiles;

+ 0
- 4
db/migrations/000014_add_column_report_date_to_ip_profile_table.up.sql View File

@@ -1,4 +0,0 @@
alter table ip_profiles add column report_date timestamp not null;

drop index ip_profiles_index_on_name;
create unique index ip_profiles_index_on_report_date_ip_information_id_and_protocol_id on ip_profiles(report_date, ip_information_id, protocol_id);

+ 0
- 12
db/migrations/000015_create_alerting_table.up.sql View File

@@ -1,12 +0,0 @@
create table alerts (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
type int not null,
reviewed boolean default false,
drop boolean default false,
alert boolean default true,
json_extra_information text not null default '{}',
ip_information_id int references ip_information(id)
);
create unique index alerts_index_on_ip_information_id_and_type on alerts(ip_information_id, type);

+ 0
- 28
db/migrations/000016_update_alerting_table.up.sql View File

@@ -1,28 +0,0 @@
ALTER TABLE public.alerts DROP CONSTRAINT IF EXISTS alerts_ip_information_id_fkey CASCADE;
DROP INDEX IF EXISTS public.alerts_index_on_ip_information_id_and_type CASCADE;
ALTER TABLE public.alerts DROP COLUMN IF EXISTS ip_information_id CASCADE;

ALTER TABLE public.alerts ADD COLUMN ip_profile_id integer;
ALTER TABLE public.alerts ADD COLUMN source_id integer;
ALTER TABLE public.alerts ADD COLUMN protocol_id integer;
ALTER TABLE public.alerts ADD COLUMN destination_id integer;
ALTER TABLE public.alerts ADD COLUMN trigger_count integer NOT NULL DEFAULT 1;
ALTER TABLE public.alerts ALTER COLUMN reviewed SET NOT NULL;
ALTER TABLE public.alerts ALTER COLUMN drop SET NOT NULL;
ALTER TABLE public.alerts ALTER COLUMN alert SET NOT NULL;

ALTER TABLE public.alerts ADD CONSTRAINT alerts_source_id_fkey FOREIGN KEY (source_id)
REFERENCES public.ip_information (id) MATCH SIMPLE
ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE public.alerts ADD CONSTRAINT alerts_protocol_id_fkey FOREIGN KEY (protocol_id)
REFERENCES public.protocols (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE public.alerts ADD CONSTRAINT alerts_ip_profile_id_fkey FOREIGN KEY (ip_profile_id)
REFERENCES public.ip_profiles (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE public.alerts ADD CONSTRAINT alerts_destination_id_fkey FOREIGN KEY (destination_id)
REFERENCES public.ip_information (id) MATCH FULL
ON DELETE NO ACTION ON UPDATE NO ACTION;

+ 0
- 6
db/migrations/000017_create_statistic_table.up.sql View File

@@ -1,6 +0,0 @@
create table statistics (
id serial primary key,
key text not null,
count real not null default 0
);
create unique index statistics_index_on_key on statistics(key);

+ 0
- 12
db/migrations/000018_create_exception_table.up.sql View File

@@ -1,12 +0,0 @@
create table exceptions (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
type int not null,
drop boolean default false,
alert boolean default true,
pattern text not null
);
create unique index exceptions_index_on_pattern on exceptions(pattern);
alter table alerts drop column drop;
alter table alerts drop column alert;

+ 0
- 1
db/migrations/000019_connections_drop_column_state.up.sql View File

@@ -1 +0,0 @@
alter table connections drop column state;

+ 0
- 6
db/migrations/000020_change_alert_and_exception_type_numbers.up.sql View File

@@ -1,6 +0,0 @@
DELETE FROM alerts WHERE type = 0;
DELETE FROM alerts WHERE type = 1;
UPDATE alerts SET type = 16 WHERE type = 2;
UPDATE alerts SET type = 32 WHERE type = 3;
UPDATE alerts SET type = 48 WHERE type = 4;
DELETE FROM alerts WHERE type = 5;

+ 0
- 11
db/migrations/000021_create_profile_table.up.sql View File

@@ -1,11 +0,0 @@
create table profiles (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
ip_information_id int references ip_information(id),
r2 real not null default 0.0,
r2_network real not null default 0.0,
ratio real not null default 1,
ratio_network real not null default 1
);
create unique index profiles_index_on_ip_information_id on profiles(ip_information_id);

+ 0
- 9
db/migrations/000022_alter_profile_table_add_constraint.up.sql View File

@@ -1,9 +0,0 @@
UPDATE profiles SET r2=0 WHERE r2='NaN';
UPDATE profiles SET r2_network=0 WHERE r2_network='NaN';
UPDATE profiles SET ratio=0 WHERE ratio='NaN';
UPDATE profiles SET ratio_network=0 WHERE ratio_network='NaN';

ALTER TABLE profiles ADD CONSTRAINT profiles_constraint_r2_nan CHECK (r2 <> 'NaN');
ALTER TABLE profiles ADD CONSTRAINT profiles_constraint_r2_network_nan CHECK (r2_network <> 'NaN');
ALTER TABLE profiles ADD CONSTRAINT profiles_constraint_ratio_nan CHECK (ratio <> 'NaN');
ALTER TABLE profiles ADD CONSTRAINT profiles_constraint_ratio_network_nan CHECK (ratio_network <> 'NaN');

+ 0
- 11
db/migrations/000023_alter_profile_table_add_columns.up.sql View File

@@ -1,11 +0,0 @@
ALTER TABLE profiles ADD COLUMN r2_daily real NOT NULL DEFAULT 0 CHECK (r2_daily <> 'NaN');
ALTER TABLE profiles ADD COLUMN r2_weekly real NOT NULL DEFAULT 0 CHECK (r2_weekly <> 'NaN');
ALTER TABLE profiles ADD COLUMN r2_monthly real NOT NULL DEFAULT 0 CHECK (r2_monthly <> 'NaN');
ALTER TABLE profiles ADD COLUMN r2_daily_network real NOT NULL DEFAULT 0 CHECK (r2_daily_network <> 'NaN');
ALTER TABLE profiles ADD COLUMN r2_weekly_network real NOT NULL DEFAULT 0 CHECK (r2_weekly_network <> 'NaN');
ALTER TABLE profiles ADD COLUMN r2_monthly_network real NOT NULL DEFAULT 0 CHECK (r2_monthly_network <> 'NaN');

ALTER TABLE profiles DROP COLUMN r2;
ALTER TABLE profiles DROP COLUMN r2_network;
ALTER TABLE profiles DROP COLUMN ratio;
ALTER TABLE profiles DROP COLUMN ratio_network;

+ 0
- 18
db/migrations/000024_fix_mlc.up.sql View File

@@ -1,18 +0,0 @@
ALTER TABLE connections RENAME COLUMN daily_count TO count;
ALTER TABLE connections DROP COLUMN created_at;
ALTER TABLE connections DROP COLUMN archived;
ALTER TABLE profiles DROP COLUMN updated_at;
ALTER TABLE ip_profiles RENAME COLUMN report_date TO created_at;
DROP INDEX profiles_index_on_ip_information_id;
UPDATE connections SET count = 1;
ALTER TABLE profiles RENAME TO r2_profiles;

create table profiles (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
ip_information_id int references ip_information(id),
anomaly_detection real not null default 1
);
create unique index profiles_index_on_ip_information_id on profiles(ip_information_id);
create unique index connections_index_on_destination_id_and_source_id_and_protocol on connections(destination_id, source_id, application_protocol_id, transport_protocol_id);

+ 0
- 8
db/migrations/000025_create_configuration_table.up.sql View File

@@ -1,8 +0,0 @@
create table configuration (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
key text not null check(key != ''),
value text not null check(value != '')
);
create unique index configuration_index_on_key on configuration(key);

+ 0
- 7
db/migrations/000026_modify_notifications.up.sql View File

@@ -1,7 +0,0 @@
delete from alerts;
alter table alerts drop column ip_profile_id;
alter table alerts drop column source_id;
alter table alerts drop column destination_id;
alter table alerts drop column protocol_id;
ALTER TABLE alerts RENAME COLUMN json_extra_information TO pattern;
ALTER TABLE alerts RENAME TO notifications;

+ 0
- 15
db/migrations/000027_create_user_table.up.sql View File

@@ -1,15 +0,0 @@
create table users (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
nickname text not null,
name text,
surname text,
bio text,
email text,
hashed_password text not null,
fingerprint text not null,
serialized_public_key text not null,
serialized_private_key text not null
);
create unique index users_index_on_nickname on users(nickname);

+ 0
- 10
db/migrations/000028_create_bearer_token_table.up.sql View File

@@ -1,10 +0,0 @@
create table bearer_tokens (
id serial primary key,
created_at timestamp not null,
user_id int references users(id),
token text not null,
note text,
level int default 0
);
create index bearer_tokens_index_on_token on bearer_tokens(token);
create index bearer_tokens_index_on_user_id on bearer_tokens(user_id);

+ 0
- 12
db/migrations/000029_create_portal_event_table.up.sql View File

@@ -1,12 +0,0 @@
create table portal_events (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
type int not null,
client_id int,
message json,
pool_uuid text not null
);
create unique index portal_events_index_on_type_pool_uuid_and_client_id on portal_events(type, pool_uuid, client_id);
create index portal_events_index_on_pool_uuid on portal_events(pool_uuid);
create index portal_events_index_on_client_id on portal_events(client_id);

+ 0
- 5
db/migrations/000030_alter_portal_event_table.up.sql View File

@@ -1,5 +0,0 @@
alter table portal_events add column pid int not null;
drop index portal_events_index_on_type_pool_uuid_and_client_id;
drop index portal_events_index_on_client_id;

create unique index portal_events_index_on_pid on portal_events(pid);

+ 0
- 3
db/migrations/000031_alter_portal_event_table.up.sql View File

@@ -1,3 +0,0 @@
alter table portal_events add column uuid_id int;
create unique index portal_events_index_on_uuid_id on portal_events(uuid_id);
alter table portal_events drop column pool_uuid;

+ 0
- 1
db/migrations/000032_alter_portal_event_table.up.sql View File

@@ -1 +0,0 @@
alter table portal_events add column ack boolean;

+ 0
- 1
db/migrations/000033_alter_portal_event_table.up.sql View File

@@ -1 +0,0 @@
drop index portal_events_index_on_uuid_id;

+ 0
- 3
db/migrations/000034_alter_portal_event_table.up.sql View File

@@ -1,3 +0,0 @@
alter table portal_events add column message_id integer not null;
alter table portal_events alter column client_id set not null;
create unique index portal_events_index_on_client_id_uuid_id_message_id on portal_events(client_id, uuid_id, message_id);

+ 0
- 5
db/migrations/000035_create_portal_migrations_table.up.sql View File

@@ -1,5 +0,0 @@
create table portal_migrations (
type integer not null,
version integer not null
);
create unique index portal_migrations_index_on_type on portal_migrations(type);

+ 0
- 3
db/migrations/000036_alter_portal_migrations_table.up.sql View File

@@ -1,3 +0,0 @@
delete from portal_migrations;
alter table portal_migrations drop column version;
alter table portal_migrations add column version timestamp not null;

+ 0
- 33
db/migrations/000037_create_pattern_table.up.sql View File

@@ -1,33 +0,0 @@
create table patterns (
id serial primary key,
updated_at timestamp not null,
raw text not null,
ip boolean not null,
url boolean not null,
url_path boolean not null,
pattern_category_id int
);
create unique index patterns_index_on_raw on patterns(raw);
create index patterns_index_on_updated_at on patterns(updated_at);
create index patterns_index_on_pattern_category_id on patterns(pattern_category_id);

create table pattern_categories (
id serial primary key,
updated_at timestamp not null,
name text not null,
parent_id int,
count int
);
create unique index pattern_categories_index_on_name on pattern_categories(name);
create index pattern_categories_index_on_updated_at on pattern_categories(updated_at);

delete from notifications;
delete from exceptions;

alter table notifications drop column pattern;
alter table exceptions drop column pattern;
alter table notifications add column pattern_id int not null;
alter table exceptions add column pattern_id int not null;

alter table notifications add constraint notifications_pattern_id_fk foreign key (pattern_id) references patterns(id);
alter table exceptions add constraint exceptions_pattern_id_fk foreign key (pattern_id) references patterns(id);

+ 0
- 2
db/migrations/000038_alter_pattern_table.up.sql View File

@@ -1,2 +0,0 @@
alter table patterns alter column pattern_category_id set not null;
alter table patterns add constraint patterns_pattern_category_id_fk foreign key (pattern_category_id) references pattern_categories(id);

+ 0
- 2
db/migrations/000039_alter_pattern_table.up.sql View File

@@ -1,2 +0,0 @@
alter table pattern_categories alter column count set not null;
alter table patterns drop column pattern_category_id;

+ 0
- 5
db/migrations/000040_create_pattern_category_lists_table.up.sql View File

@@ -1,5 +0,0 @@
create table pattern_category_lists (
pattern_id int not null references patterns(id),
category_id int not null references pattern_categories(id)
);
create unique index pattern_category_lists_index_on_pattern_id_category_id on pattern_category_lists(pattern_id, category_id);

+ 0
- 15
db/migrations/000041_alter_pattern_category_lists_table.up.sql View File

@@ -1,15 +0,0 @@
alter table pattern_category_lists drop constraint pattern_category_lists_pattern_id_fkey;
alter table pattern_category_lists drop constraint pattern_category_lists_category_id_fkey;
alter table pattern_category_lists add constraint pattern_category_lists_pattern_id_fkey foreign key (pattern_id) references patterns (id) match simple on delete cascade on update no action;
alter table pattern_category_lists add constraint pattern_category_lists_category_id_fkey foreign key (category_id) references pattern_categories (id) match simple on delete cascade on update no action;

create function clean_up_after_pattern_delete() returns trigger language PLPGSQL as
$$
begin
if not exists (select from pattern_category_lists where category_id = OLD.category_id) then
delete from pattern_categories where id = OLD.category_id;
end if;
return OLD;
END;
$$;
create trigger clean_up_after_pattern_delete after delete on pattern_category_lists for each row execute procedure clean_up_after_pattern_delete();

+ 0
- 1
db/migrations/000042_alter_pattern_categories_table.up.sql View File

@@ -1 +0,0 @@
alter table pattern_categories add column enabled boolean not null default false;

+ 0
- 21
db/migrations/000043_create_network_interface_table.up.sql View File

@@ -1,21 +0,0 @@
create table networks (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
name text not null,
network cidr not null,
dhcp boolean not null default false,
dns boolean not null default true
);
create unique index networks_network on networks(network);

create table network_interfaces (
id serial primary key,
created_at timestamp not null,
updated_at timestamp not null,
name text not null,
network_id int references networks(id),
wireless boolean not null default false
);
create unique index network_interfaces_name on network_interfaces(name);
create index network_interfaces_wireless on network_interfaces(wireless);

+ 0
- 2
db/migrations/000044_alter_networks_table.up.sql View File

@@ -1,2 +0,0 @@
alter table networks add column address inet not null;
create unique index networks_address on networks(address);

+ 0
- 8
db/migrations/000045_alter_networks_table.up.sql View File

@@ -1,8 +0,0 @@
alter table networks add column client boolean not null default false;
alter table networks add constraint check_dhcp_dns_and_client_relation check (((dns or dhcp) and not client) or (not dns and not dhcp or client));
alter table networks alter column network drop not null;
alter table networks alter column address drop not null;
drop index networks_network;
drop index networks_address;
create unique index networks_network on networks(network) where network is not null;
create unique index networks_address on networks(address) where address is not null;

+ 0
- 1
db/migrations/000046_alter_networks_table.up.sql View File

@@ -1 +0,0 @@
create unique index networks_name on networks(name);

+ 0
- 1
db/migrations/000047_alter_network_interfaces_table.up.sql View File

@@ -1 +0,0 @@
alter table network_interfaces add column default_gateway boolean not null default false;

+ 0
- 3
db/migrations/000048_alter_network_interfaces_table.up.sql View File

@@ -1,3 +0,0 @@
alter table network_interfaces add column physical boolean not null default false;
alter table network_interfaces add column bridge boolean not null default false;
alter table network_interfaces add column tun boolean not null default false;

+ 0
- 1
db/migrations/000049_alter_network_interfaces_table.up.sql View File

@@ -1 +0,0 @@
alter table network_interfaces add column bridge_id text;

+ 0
- 1
db/migrations/000050_alter_network_interfaces_table.up.sql View File

@@ -1 +0,0 @@
alter table network_interfaces rename column bridge to bridge_master;

+ 429
- 0
db/migrations/000050_merged_initial_database.up.sql View File

@@ -0,0 +1,429 @@
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
CREATE FUNCTION public.clean_up_after_pattern_delete() RETURNS trigger
LANGUAGE plpgsql
AS $$
begin
if not exists (select from pattern_category_lists where category_id = OLD.category_id) then
delete from pattern_categories where id = OLD.category_id;
end if;
return OLD;
END;
$$;
SET default_tablespace = '';
SET default_table_access_method = heap;
CREATE TABLE public.notifications (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
type integer NOT NULL,
reviewed boolean DEFAULT false NOT NULL,
trigger_count integer DEFAULT 1 NOT NULL,
pattern_id integer NOT NULL
);
CREATE SEQUENCE public.alerts_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.alerts_id_seq OWNED BY public.notifications.id;
CREATE TABLE public.bearer_tokens (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
user_id integer,
token text NOT NULL,
note text,
level integer DEFAULT 0
);
CREATE SEQUENCE public.bearer_tokens_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.bearer_tokens_id_seq OWNED BY public.bearer_tokens.id;
CREATE TABLE public.configuration (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
key text NOT NULL,
value text NOT NULL,
CONSTRAINT configuration_key_check CHECK ((key <> ''::text)),
CONSTRAINT configuration_value_check CHECK ((value <> ''::text))
);
CREATE SEQUENCE public.configuration_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.configuration_id_seq OWNED BY public.configuration.id;
CREATE TABLE public.connections (
id integer NOT NULL,
updated_at timestamp without time zone NOT NULL,
destination_id integer DEFAULT 0 NOT NULL,
source_id integer DEFAULT 0 NOT NULL,
count integer DEFAULT 1 NOT NULL,
application_protocol_id integer,
transport_protocol_id integer
);
CREATE SEQUENCE public.connections_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.connections_id_seq OWNED BY public.connections.id;
CREATE TABLE public.exceptions (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
type integer NOT NULL,
drop boolean DEFAULT false,
alert boolean DEFAULT true,
pattern_id integer NOT NULL
);
CREATE SEQUENCE public.exceptions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.exceptions_id_seq OWNED BY public.exceptions.id;
CREATE TABLE public.ip_information (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
ip text NOT NULL,
reverse_dns text DEFAULT ''::text NOT NULL,
net_bios text DEFAULT ''::text NOT NULL,
country text DEFAULT ''::text NOT NULL,
european_union boolean DEFAULT false NOT NULL,
anonymous_proxy boolean DEFAULT false NOT NULL,
satellite_provider boolean DEFAULT false NOT NULL,
mac text NOT NULL
);
CREATE SEQUENCE public.ip_information_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.ip_information_id_seq OWNED BY public.ip_information.id;
CREATE TABLE public.ip_profiles (
id integer NOT NULL,
ip_information_id integer,
protocol_id integer,
weight real DEFAULT 0 NOT NULL,
created_at timestamp without time zone NOT NULL
);
CREATE SEQUENCE public.ip_profiles_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.ip_profiles_id_seq OWNED BY public.ip_profiles.id;
CREATE TABLE public.network_interfaces (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
name text NOT NULL,
network_id integer,
wireless boolean DEFAULT false NOT NULL,
default_gateway boolean DEFAULT false NOT NULL,
physical boolean DEFAULT false NOT NULL,
bridge_master boolean DEFAULT false NOT NULL,
tun boolean DEFAULT false NOT NULL,
bridge_id text
);
CREATE SEQUENCE public.network_interfaces_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.network_interfaces_id_seq OWNED BY public.network_interfaces.id;
CREATE TABLE public.networks (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
name text NOT NULL,
network cidr,
dhcp boolean DEFAULT false NOT NULL,
dns boolean DEFAULT true NOT NULL,
address inet,
client boolean DEFAULT false NOT NULL,
CONSTRAINT check_dhcp_dns_and_client_relation CHECK ((((dns OR dhcp) AND (NOT client)) OR (((NOT dns) AND (NOT dhcp)) OR client)))
);
CREATE SEQUENCE public.networks_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.networks_id_seq OWNED BY public.networks.id;
CREATE TABLE public.pattern_categories (
id integer NOT NULL,
updated_at timestamp without time zone NOT NULL,
name text NOT NULL,
parent_id integer,
count integer NOT NULL,
enabled boolean DEFAULT false NOT NULL
);
CREATE SEQUENCE public.pattern_categories_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.pattern_categories_id_seq OWNED BY public.pattern_categories.id;
CREATE TABLE public.pattern_category_lists (
pattern_id integer NOT NULL,
category_id integer NOT NULL
);
CREATE TABLE public.patterns (
id integer NOT NULL,
updated_at timestamp without time zone NOT NULL,
raw text NOT NULL,
ip boolean NOT NULL,
url boolean NOT NULL,
url_path boolean NOT NULL
);
CREATE SEQUENCE public.patterns_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.patterns_id_seq OWNED BY public.patterns.id;
CREATE TABLE public.portal_events (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
type integer NOT NULL,
client_id integer NOT NULL,
message json,
pid integer NOT NULL,
uuid_id integer,
ack boolean,
message_id integer NOT NULL
);
CREATE SEQUENCE public.portal_events_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.portal_events_id_seq OWNED BY public.portal_events.id;
CREATE TABLE public.portal_migrations (
type integer NOT NULL,
version timestamp without time zone NOT NULL
);
CREATE TABLE public.profiles (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
ip_information_id integer,
anomaly_detection real DEFAULT 1 NOT NULL
);
CREATE TABLE public.r2_profiles (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
ip_information_id integer,
r2_daily real DEFAULT 0 NOT NULL,
r2_weekly real DEFAULT 0 NOT NULL,
r2_monthly real DEFAULT 0 NOT NULL,
r2_daily_network real DEFAULT 0 NOT NULL,
r2_weekly_network real DEFAULT 0 NOT NULL,
r2_monthly_network real DEFAULT 0 NOT NULL,
CONSTRAINT profiles_r2_daily_check CHECK ((r2_daily <> 'NaN'::real)),
CONSTRAINT profiles_r2_daily_network_check CHECK ((r2_daily_network <> 'NaN'::real)),
CONSTRAINT profiles_r2_monthly_check CHECK ((r2_monthly <> 'NaN'::real)),
CONSTRAINT profiles_r2_monthly_network_check CHECK ((r2_monthly_network <> 'NaN'::real)),
CONSTRAINT profiles_r2_weekly_check CHECK ((r2_weekly <> 'NaN'::real)),
CONSTRAINT profiles_r2_weekly_network_check CHECK ((r2_weekly_network <> 'NaN'::real))
);
CREATE SEQUENCE public.profiles_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.profiles_id_seq OWNED BY public.r2_profiles.id;
CREATE SEQUENCE public.profiles_id_seq1
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.profiles_id_seq1 OWNED BY public.profiles.id;
CREATE TABLE public.protocols (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
name text NOT NULL
);
CREATE SEQUENCE public.protocols_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.protocols_id_seq OWNED BY public.protocols.id;
CREATE TABLE public.statistics (
id integer NOT NULL,
key text NOT NULL,
count real DEFAULT 0 NOT NULL
);
CREATE SEQUENCE public.statistics_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.statistics_id_seq OWNED BY public.statistics.id;
CREATE TABLE public.users (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
nickname text NOT NULL,
name text,
surname text,
bio text,
email text,
hashed_password text NOT NULL,
fingerprint text NOT NULL,
serialized_public_key text NOT NULL,
serialized_private_key text NOT NULL
);
CREATE SEQUENCE public.users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
ALTER TABLE ONLY public.bearer_tokens ALTER COLUMN id SET DEFAULT nextval('public.bearer_tokens_id_seq'::regclass);
ALTER TABLE ONLY public.configuration ALTER COLUMN id SET DEFAULT nextval('public.configuration_id_seq'::regclass);
ALTER TABLE ONLY public.connections ALTER COLUMN id SET DEFAULT nextval('public.connections_id_seq'::regclass);
ALTER TABLE ONLY public.exceptions ALTER COLUMN id SET DEFAULT nextval('public.exceptions_id_seq'::regclass);
ALTER TABLE ONLY public.ip_information ALTER COLUMN id SET DEFAULT nextval('public.ip_information_id_seq'::regclass);
ALTER TABLE ONLY public.ip_profiles ALTER COLUMN id SET DEFAULT nextval('public.ip_profiles_id_seq'::regclass);
ALTER TABLE ONLY public.network_interfaces ALTER COLUMN id SET DEFAULT nextval('public.network_interfaces_id_seq'::regclass);
ALTER TABLE ONLY public.networks ALTER COLUMN id SET DEFAULT nextval('public.networks_id_seq'::regclass);
ALTER TABLE ONLY public.notifications ALTER COLUMN id SET DEFAULT nextval('public.alerts_id_seq'::regclass);
ALTER TABLE ONLY public.pattern_categories ALTER COLUMN id SET DEFAULT nextval('public.pattern_categories_id_seq'::regclass);
ALTER TABLE ONLY public.patterns ALTER COLUMN id SET DEFAULT nextval('public.patterns_id_seq'::regclass);
ALTER TABLE ONLY public.portal_events ALTER COLUMN id SET DEFAULT nextval('public.portal_events_id_seq'::regclass);
ALTER TABLE ONLY public.profiles ALTER COLUMN id SET DEFAULT nextval('public.profiles_id_seq1'::regclass);
ALTER TABLE ONLY public.protocols ALTER COLUMN id SET DEFAULT nextval('public.protocols_id_seq'::regclass);
ALTER TABLE ONLY public.r2_profiles ALTER COLUMN id SET DEFAULT nextval('public.profiles_id_seq'::regclass);
ALTER TABLE ONLY public.statistics ALTER COLUMN id SET DEFAULT nextval('public.statistics_id_seq'::regclass);
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT alerts_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bearer_tokens
ADD CONSTRAINT bearer_tokens_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.configuration
ADD CONSTRAINT configuration_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.connections
ADD CONSTRAINT connections_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.exceptions
ADD CONSTRAINT exceptions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.ip_information
ADD CONSTRAINT ip_information_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.ip_profiles
ADD CONSTRAINT ip_profiles_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.network_interfaces
ADD CONSTRAINT network_interfaces_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.networks
ADD CONSTRAINT networks_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.pattern_categories
ADD CONSTRAINT pattern_categories_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.patterns
ADD CONSTRAINT patterns_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.portal_events
ADD CONSTRAINT portal_events_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.r2_profiles
ADD CONSTRAINT profiles_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.profiles
ADD CONSTRAINT profiles_pkey1 PRIMARY KEY (id);
ALTER TABLE ONLY public.protocols
ADD CONSTRAINT protocols_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.statistics
ADD CONSTRAINT statistics_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
CREATE INDEX bearer_tokens_index_on_token ON public.bearer_tokens USING btree (token);
CREATE INDEX bearer_tokens_index_on_user_id ON public.bearer_tokens USING btree (user_id);
CREATE UNIQUE INDEX configuration_index_on_key ON public.configuration USING btree (key);
CREATE UNIQUE INDEX connection_infos_index_on_ip ON public.ip_information USING btree (ip);
CREATE UNIQUE INDEX connections_index_on_destination_id_and_source_id_and_protocol ON public.connections USING btree (destination_id, source_id, application_protocol_id, transport_protocol_id);
CREATE UNIQUE INDEX ip_profiles_index_on_report_date_ip_information_id_and_protocol ON public.ip_profiles USING btree (created_at, ip_information_id, protocol_id);
CREATE UNIQUE INDEX network_interfaces_name ON public.network_interfaces USING btree (name);
CREATE INDEX network_interfaces_wireless ON public.network_interfaces USING btree (wireless);
CREATE UNIQUE INDEX networks_address ON public.networks USING btree (address) WHERE (address IS NOT NULL);
CREATE UNIQUE INDEX networks_name ON public.networks USING btree (name);
CREATE UNIQUE INDEX networks_network ON public.networks USING btree (network) WHERE (network IS NOT NULL);
CREATE UNIQUE INDEX pattern_categories_index_on_name ON public.pattern_categories USING btree (name);
CREATE INDEX pattern_categories_index_on_updated_at ON public.pattern_categories USING btree (updated_at);
CREATE UNIQUE INDEX pattern_category_lists_index_on_pattern_id_category_id ON public.pattern_category_lists USING btree (pattern_id, category_id);
CREATE UNIQUE INDEX patterns_index_on_raw ON public.patterns USING btree (raw);
CREATE INDEX patterns_index_on_updated_at ON public.patterns USING btree (updated_at);
CREATE UNIQUE INDEX portal_events_index_on_client_id_uuid_id_message_id ON public.portal_events USING btree (client_id, uuid_id, message_id);
CREATE UNIQUE INDEX portal_events_index_on_pid ON public.portal_events USING btree (pid);
CREATE UNIQUE INDEX portal_migrations_index_on_type ON public.portal_migrations USING btree (type);
CREATE UNIQUE INDEX profiles_index_on_ip_information_id ON public.profiles USING btree (ip_information_id);
CREATE UNIQUE INDEX protocols_index_on_name ON public.protocols USING btree (name);
CREATE UNIQUE INDEX statistics_index_on_key ON public.statistics USING btree (key);
CREATE UNIQUE INDEX users_index_on_nickname ON public.users USING btree (nickname);
CREATE TRIGGER clean_up_after_pattern_delete AFTER DELETE ON public.pattern_category_lists FOR EACH ROW EXECUTE FUNCTION public.clean_up_after_pattern_delete();
ALTER TABLE ONLY public.bearer_tokens
ADD CONSTRAINT bearer_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
ALTER TABLE ONLY public.connections
ADD CONSTRAINT connections_application_protocol_id_fk FOREIGN KEY (application_protocol_id) REFERENCES public.protocols(id);
ALTER TABLE ONLY public.connections
ADD CONSTRAINT connections_transport_protocol_id_fk FOREIGN KEY (transport_protocol_id) REFERENCES public.protocols(id);
ALTER TABLE ONLY public.exceptions
ADD CONSTRAINT exceptions_pattern_id_fk FOREIGN KEY (pattern_id) REFERENCES public.patterns(id);
ALTER TABLE ONLY public.ip_profiles
ADD CONSTRAINT ip_profiles_ip_information_id_fkey FOREIGN KEY (ip_information_id) REFERENCES public.ip_information(id);
ALTER TABLE ONLY public.ip_profiles
ADD CONSTRAINT ip_profiles_protocol_id_fkey FOREIGN KEY (protocol_id) REFERENCES public.protocols(id);
ALTER TABLE ONLY public.network_interfaces
ADD CONSTRAINT network_interfaces_network_id_fkey FOREIGN KEY (network_id) REFERENCES public.networks(id);
ALTER TABLE ONLY public.notifications
ADD CONSTRAINT notifications_pattern_id_fk FOREIGN KEY (pattern_id) REFERENCES public.patterns(id);
ALTER TABLE ONLY public.pattern_category_lists
ADD CONSTRAINT pattern_category_lists_category_id_fkey FOREIGN KEY (category_id) REFERENCES public.pattern_categories(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.pattern_category_lists
ADD CONSTRAINT pattern_category_lists_pattern_id_fkey FOREIGN KEY (pattern_id) REFERENCES public.patterns(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.r2_profiles
ADD CONSTRAINT profiles_ip_information_id_fkey FOREIGN KEY (ip_information_id) REFERENCES public.ip_information(id);
ALTER TABLE ONLY public.profiles
ADD CONSTRAINT profiles_ip_information_id_fkey1 FOREIGN KEY (ip_information_id) REFERENCES public.ip_information(id);

Loading…
Cancel
Save