-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup TimeScaleDB and Grafana with some metrics (#124)
- Loading branch information
Showing
13 changed files
with
289 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
data/database | ||
data/grafana | ||
config.toml | ||
|
||
# editors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# type: ignore | ||
|
||
"""Update scheme | ||
Revision ID: 075fbc7011f0 | ||
Revises: b94894dcf45a | ||
Create Date: 2023-12-17 05:17:20.777664 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '075fbc7011f0' | ||
down_revision = 'b94894dcf45a' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('ts_command_usage', sa.Column('guild_id', sa.BIGINT(), nullable=True)) | ||
op.drop_constraint('ts_command_usage_guild_fkey', 'ts_command_usage', type_='foreignkey') | ||
op.create_foreign_key(None, 'ts_command_usage', 'guild', ['guild_id'], ['guild_id']) | ||
op.drop_column('ts_command_usage', 'guild') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('ts_command_usage', sa.Column('guild', sa.BIGINT(), autoincrement=False, nullable=False)) | ||
op.drop_constraint(None, 'ts_command_usage', type_='foreignkey') | ||
op.create_foreign_key('ts_command_usage_guild_fkey', 'ts_command_usage', 'guild', ['guild'], ['guild_id']) | ||
op.drop_column('ts_command_usage', 'guild_id') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# type: ignore | ||
|
||
"""Add timeseries tables | ||
Revision ID: b94894dcf45a | ||
Revises: d5d3bface80d | ||
Create Date: 2023-08-20 14:33:13.870224 | ||
""" | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b94894dcf45a" | ||
down_revision = "d5d3bface80d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"ts_guild_count", | ||
sa.Column("ts", sa.TIMESTAMP(), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("value", sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint("ts"), | ||
) | ||
op.create_table( | ||
"ts_command_usage", | ||
sa.Column("ts", sa.TIMESTAMP(), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
sa.Column("guild", sa.BigInteger(), nullable=False), | ||
sa.Column("data", postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["guild"], | ||
["guild.guild_id"], | ||
), | ||
sa.PrimaryKeyConstraint("ts"), | ||
) | ||
op.create_table( | ||
"ts_setting_update", | ||
sa.Column("ts", sa.TIMESTAMP(), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("guild_id", sa.BigInteger(), nullable=False), | ||
sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
sa.Column("data", postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["guild_id"], | ||
["guild.guild_id"], | ||
), | ||
sa.PrimaryKeyConstraint("ts"), | ||
) | ||
op.create_table( | ||
"ts_poll_modification", | ||
sa.Column("ts", sa.TIMESTAMP(), server_default=sa.text("now()"), nullable=False), | ||
sa.Column("user_id", sa.BigInteger(), nullable=False), | ||
sa.Column("poll_id", sa.Integer(), nullable=False), | ||
sa.Column("data", postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["poll_id"], | ||
["poll.id"], | ||
), | ||
sa.PrimaryKeyConstraint("ts"), | ||
) | ||
op.drop_table("usage") | ||
# ### end Alembic commands ### | ||
|
||
op.execute("CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;") | ||
op.execute("SELECT create_hypertable('ts_guild_count','ts');") | ||
op.execute("SELECT create_hypertable('ts_command_usage','ts');") | ||
op.execute("SELECT create_hypertable('ts_setting_update','ts');") | ||
op.execute("SELECT create_hypertable('ts_poll_modification','ts');") | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"usage", | ||
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), | ||
sa.Column("type", postgresql.ENUM("SLASHCOMMAND", name="usagetype"), autoincrement=False, nullable=False), | ||
sa.Column("details", sa.VARCHAR(), autoincrement=False, nullable=False), | ||
sa.Column("user_id", sa.BIGINT(), autoincrement=False, nullable=False), | ||
sa.Column("guild_id", sa.BIGINT(), autoincrement=False, nullable=False), | ||
sa.ForeignKeyConstraint(["guild_id"], ["guild.guild_id"], name="usage_guild_id_fkey"), | ||
sa.ForeignKeyConstraint(["user_id"], ["user.user_id"], name="usage_user_id_fkey"), | ||
sa.PrimaryKeyConstraint("id", name="usage_pkey"), | ||
) | ||
op.drop_table("ts_poll_modification") | ||
op.drop_table("ts_setting_update") | ||
op.drop_table("ts_command_usage") | ||
op.drop_table("ts_guild_count") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ services: | |
- 8080:8080 | ||
|
||
database: | ||
expose: | ||
- 5432 | ||
ports: | ||
- 5432:5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.