Add initial alembic migration
Graham Williamson committed
Jul 12, 2023 at 21:55 UTC
5adda2867ebf69fc733e4232df1ad9a476aff893
4 files changed
+194
backend/migrations/README
new
+1
@@ -0,0 +1 @@
1
+Single-database configuration for Flask.
backend/migrations/alembic.ini
new
+50
@@ -0,0 +1,50 @@
1
+# A generic, single database configuration.
2
+
3
+[alembic]
4
+# template used to generate migration files
5
+# file_template = %%(rev)s_%%(slug)s
6
+
7
+# set to 'true' to run the environment during
8
+# the 'revision' command, regardless of autogenerate
9
+# revision_environment = false
10
+
11
+
12
+# Logging configuration
13
+[loggers]
14
+keys = root,sqlalchemy,alembic,flask_migrate
15
+
16
+[handlers]
17
+keys = console
18
+
19
+[formatters]
20
+keys = generic
21
+
22
+[logger_root]
23
+level = WARN
24
+handlers = console
25
+qualname =
26
+
27
+[logger_sqlalchemy]
28
+level = WARN
29
+handlers =
30
+qualname = sqlalchemy.engine
31
+
32
+[logger_alembic]
33
+level = INFO
34
+handlers =
35
+qualname = alembic
36
+
37
+[logger_flask_migrate]
38
+level = INFO
39
+handlers =
40
+qualname = flask_migrate
41
+
42
+[handler_console]
43
+class = StreamHandler
44
+args = (sys.stderr,)
45
+level = NOTSET
46
+formatter = generic
47
+
48
+[formatter_generic]
49
+format = %(levelname)-5.5s [%(name)s] %(message)s
50
+datefmt = %H:%M:%S
backend/migrations/script.py.mako
new
+24
@@ -0,0 +1,24 @@
1
+"""${message}
2
+
3
+Revision ID: ${up_revision}
4
+Revises: ${down_revision | comma,n}
5
+Create Date: ${create_date}
6
+
7
+"""
8
+from alembic import op
9
+import sqlalchemy as sa
10
+${imports if imports else ""}
11
+
12
+# revision identifiers, used by Alembic.
13
+revision = ${repr(up_revision)}
14
+down_revision = ${repr(down_revision)}
15
+branch_labels = ${repr(branch_labels)}
16
+depends_on = ${repr(depends_on)}
17
+
18
+
19
+def upgrade():
20
+ ${upgrades if upgrades else "pass"}
21
+
22
+
23
+def downgrade():
24
+ ${downgrades if downgrades else "pass"}
backend/migrations/versions/0381c0088cbe_initial_migration.py
new
+119
@@ -0,0 +1,119 @@
1
+"""Initial migration.
2
+
3
+Revision ID: 0381c0088cbe
4
+Revises:
5
+Create Date: 2023-07-11 13:24:04.087035
6
+
7
+"""
8
+import sqlalchemy as sa
9
+from alembic import op
10
+
11
+# revision identifiers, used by Alembic.
12
+revision = "0381c0088cbe"
13
+down_revision = None
14
+branch_labels = None
15
+depends_on = None
16
+
17
+
18
+def upgrade():
19
+ # ### commands auto generated by Alembic - please adjust! ###
20
+ op.create_table(
21
+ "agent_metadata",
22
+ sa.Column("id", sa.Integer(), nullable=False),
23
+ sa.Column("agent_id", sa.String(length=100), nullable=True),
24
+ sa.Column("ip_address", sa.String(length=100), nullable=True),
25
+ sa.Column("os", sa.String(length=100), nullable=True),
26
+ sa.Column("hostname", sa.String(length=100), nullable=True),
27
+ sa.Column("critical_asset", sa.Boolean(), nullable=True),
28
+ sa.Column("last_seen", sa.DateTime(), nullable=True),
29
+ sa.PrimaryKeyConstraint("id"),
30
+ )
31
+ op.create_table(
32
+ "artifact",
33
+ sa.Column("id", sa.Integer(), nullable=False),
34
+ sa.Column("artifact_name", sa.String(length=100), nullable=True),
35
+ sa.Column("artifact_results", sa.TEXT(), nullable=True),
36
+ sa.Column("hostname", sa.String(length=100), nullable=True),
37
+ sa.PrimaryKeyConstraint("id"),
38
+ )
39
+ op.create_table(
40
+ "case",
41
+ sa.Column("id", sa.Integer(), nullable=False),
42
+ sa.Column("case_id", sa.Integer(), nullable=True),
43
+ sa.Column("case_name", sa.String(length=100), nullable=True),
44
+ sa.Column("agents", sa.String(length=1000), nullable=True),
45
+ sa.PrimaryKeyConstraint("id"),
46
+ )
47
+ op.create_table(
48
+ "connectors",
49
+ sa.Column("id", sa.Integer(), nullable=False),
50
+ sa.Column("connector_name", sa.String(length=100), nullable=True),
51
+ sa.Column("connector_type", sa.String(length=100), nullable=True),
52
+ sa.Column("connector_url", sa.String(length=100), nullable=True),
53
+ sa.Column("connector_last_updated", sa.DateTime(), nullable=True),
54
+ sa.Column("connector_username", sa.String(length=100), nullable=True),
55
+ sa.Column("connector_password", sa.String(length=100), nullable=True),
56
+ sa.Column("connector_api_key", sa.String(length=100), nullable=True),
57
+ sa.PrimaryKeyConstraint("id"),
58
+ sa.UniqueConstraint("connector_name"),
59
+ )
60
+ op.create_table(
61
+ "connectors_available",
62
+ sa.Column("id", sa.Integer(), nullable=False),
63
+ sa.Column("connector_name", sa.String(length=100), nullable=True),
64
+ sa.Column("connector_description", sa.String(length=100), nullable=True),
65
+ sa.Column("connector_supports", sa.String(length=100), nullable=True),
66
+ sa.Column("connector_configured", sa.Boolean(), nullable=True),
67
+ sa.Column("connector_verified", sa.Boolean(), nullable=True),
68
+ sa.PrimaryKeyConstraint("id"),
69
+ sa.UniqueConstraint("connector_name"),
70
+ )
71
+ op.create_table(
72
+ "disabled_rules",
73
+ sa.Column("id", sa.Integer(), nullable=False),
74
+ sa.Column("rule_id", sa.String(length=100), nullable=True),
75
+ sa.Column("previous_level", sa.String(length=1000), nullable=True),
76
+ sa.Column("new_level", sa.String(length=1000), nullable=True),
77
+ sa.Column("reason_for_disabling", sa.String(length=100), nullable=True),
78
+ sa.Column("date_disabled", sa.DateTime(), nullable=True),
79
+ sa.Column("length_of_time", sa.Integer(), nullable=True),
80
+ sa.PrimaryKeyConstraint("id"),
81
+ )
82
+ op.create_table(
83
+ "graylog_metrics_allocation",
84
+ sa.Column("id", sa.Integer(), nullable=False),
85
+ sa.Column("input_usage", sa.Float(), nullable=True),
86
+ sa.Column("output_usage", sa.Float(), nullable=True),
87
+ sa.Column("processor_usage", sa.Float(), nullable=True),
88
+ sa.Column("input_1_sec_rate", sa.Float(), nullable=True),
89
+ sa.Column("output_1_sec_rate", sa.Float(), nullable=True),
90
+ sa.Column("total_input", sa.Float(), nullable=True),
91
+ sa.Column("total_output", sa.Float(), nullable=True),
92
+ sa.Column("timestamp", sa.DateTime(), nullable=True),
93
+ sa.PrimaryKeyConstraint("id"),
94
+ )
95
+ op.create_table(
96
+ "wazuh_indexer_allocation",
97
+ sa.Column("id", sa.Integer(), nullable=False),
98
+ sa.Column("node", sa.String(length=100), nullable=True),
99
+ sa.Column("disk_used", sa.Float(), nullable=True),
100
+ sa.Column("disk_available", sa.Float(), nullable=True),
101
+ sa.Column("disk_total", sa.Float(), nullable=True),
102
+ sa.Column("disk_percent", sa.Float(), nullable=True),
103
+ sa.Column("timestamp", sa.DateTime(), nullable=True),
104
+ sa.PrimaryKeyConstraint("id"),
105
+ )
106
+ # ### end Alembic commands ###
107
+
108
+
109
+def downgrade():
110
+ # ### commands auto generated by Alembic - please adjust! ###
111
+ op.drop_table("wazuh_indexer_allocation")
112
+ op.drop_table("graylog_metrics_allocation")
113
+ op.drop_table("disabled_rules")
114
+ op.drop_table("connectors_available")
115
+ op.drop_table("connectors")
116
+ op.drop_table("case")
117
+ op.drop_table("artifact")
118
+ op.drop_table("agent_metadata")
119
+ # ### end Alembic commands ###