diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d395e98..975ececd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,16 @@ repos: args: [ --fix ] # Run the formatter. - id: ruff-format + - repo: local + hooks: + # Check there are no migrations missing + - id: alembic + name: alembic + stages: [commit] + types: [python] + entry: alembic -c core/db/alembic.ini check + language: system + pass_filenames: false - repo: local hooks: # Run the tests diff --git a/core/db/migrations/versions/06e603d6e19a_add_state_action_info.py b/core/db/migrations/versions/06e603d6e19a_add_state_action_info.py deleted file mode 100644 index a255c190..00000000 --- a/core/db/migrations/versions/06e603d6e19a_add_state_action_info.py +++ /dev/null @@ -1,34 +0,0 @@ -"""add state action info - -Revision ID: 06e603d6e19a -Revises: dbc3fd7ef89b -Create Date: 2024-05-25 10:33:34.535522 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "06e603d6e19a" -down_revision: Union[str, None] = "dbc3fd7ef89b" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("project_states", schema=None) as batch_op: - batch_op.add_column(sa.Column("action", sa.String(), nullable=True)) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("project_states", schema=None) as batch_op: - batch_op.drop_column("action") - - # ### end Alembic commands ### diff --git a/core/db/migrations/versions/4f79e6952354_added_complexity_to_specification.py b/core/db/migrations/versions/4f79e6952354_added_complexity_to_specification.py deleted file mode 100644 index c089eb9d..00000000 --- a/core/db/migrations/versions/4f79e6952354_added_complexity_to_specification.py +++ /dev/null @@ -1,34 +0,0 @@ -"""added complexity to specification - -Revision ID: 4f79e6952354 -Revises: 5b04ea6afce5 -Create Date: 2024-05-16 18:01:49.024811 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "4f79e6952354" -down_revision: Union[str, None] = "5b04ea6afce5" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("specifications", schema=None) as batch_op: - batch_op.add_column(sa.Column("complexity", sa.String(), server_default="hard", nullable=False)) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("specifications", schema=None) as batch_op: - batch_op.drop_column("complexity") - - # ### end Alembic commands ### diff --git a/core/db/migrations/versions/5b04ea6afce5_add_agent_info_to_llm_request_log.py b/core/db/migrations/versions/5b04ea6afce5_add_agent_info_to_llm_request_log.py deleted file mode 100644 index 3ca14643..00000000 --- a/core/db/migrations/versions/5b04ea6afce5_add_agent_info_to_llm_request_log.py +++ /dev/null @@ -1,34 +0,0 @@ -"""add agent info to llm request log - -Revision ID: 5b04ea6afce5 -Revises: fd206d3095d0 -Create Date: 2024-05-12 11:07:40.271217 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "5b04ea6afce5" -down_revision: Union[str, None] = "fd206d3095d0" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("llm_requests", schema=None) as batch_op: - batch_op.add_column(sa.Column("agent", sa.String(), nullable=True)) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("llm_requests", schema=None) as batch_op: - batch_op.drop_column("agent") - - # ### end Alembic commands ### diff --git a/core/db/migrations/versions/dbc3fd7ef89b_record_prompt_data.py b/core/db/migrations/versions/dbc3fd7ef89b_record_prompt_data.py deleted file mode 100644 index 01c01b73..00000000 --- a/core/db/migrations/versions/dbc3fd7ef89b_record_prompt_data.py +++ /dev/null @@ -1,34 +0,0 @@ -"""record prompt data - -Revision ID: dbc3fd7ef89b -Revises: 4f79e6952354 -Create Date: 2024-05-23 17:02:15.386028 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "dbc3fd7ef89b" -down_revision: Union[str, None] = "4f79e6952354" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("llm_requests", schema=None) as batch_op: - batch_op.add_column(sa.Column("prompts", sa.JSON(), server_default="[]", nullable=False)) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("llm_requests", schema=None) as batch_op: - batch_op.drop_column("prompts") - - # ### end Alembic commands ### diff --git a/core/db/migrations/versions/e7b54beadf8f_initial.py b/core/db/migrations/versions/e7b54beadf8f_initial.py deleted file mode 100644 index 1d9db050..00000000 --- a/core/db/migrations/versions/e7b54beadf8f_initial.py +++ /dev/null @@ -1,120 +0,0 @@ -"""initial - -Revision ID: e7b54beadf8f -Revises: -Create Date: 2024-05-06 09:38:05.391674 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "e7b54beadf8f" -down_revision: Union[str, None] = None -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "file_contents", - sa.Column("id", sa.String(), nullable=False), - sa.Column("content", sa.String(), nullable=False), - sa.PrimaryKeyConstraint("id", name=op.f("pk_file_contents")), - ) - op.create_table( - "projects", - sa.Column("id", sa.Uuid(), nullable=False), - sa.Column("name", sa.String(), nullable=False), - sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), - sa.Column("folder_name", sa.String(), nullable=False), - sa.PrimaryKeyConstraint("id", name=op.f("pk_projects")), - ) - op.create_table( - "specifications", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("description", sa.String(), nullable=False), - sa.Column("architecture", sa.String(), nullable=False), - sa.Column("system_dependencies", sa.JSON(), nullable=False), - sa.Column("package_dependencies", sa.JSON(), nullable=False), - sa.Column("template", sa.String(), nullable=True), - sa.PrimaryKeyConstraint("id", name=op.f("pk_specifications")), - ) - op.create_table( - "branches", - sa.Column("id", sa.Uuid(), nullable=False), - sa.Column("project_id", sa.Uuid(), nullable=False), - sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), - sa.Column("name", sa.String(), nullable=False), - sa.ForeignKeyConstraint( - ["project_id"], ["projects.id"], name=op.f("fk_branches_project_id_projects"), ondelete="CASCADE" - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_branches")), - ) - op.create_table( - "project_states", - sa.Column("id", sa.Uuid(), nullable=False), - sa.Column("branch_id", sa.Uuid(), nullable=False), - sa.Column("prev_state_id", sa.Uuid(), nullable=True), - sa.Column("specification_id", sa.Integer(), nullable=False), - sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), - sa.Column("step_index", sa.Integer(), server_default="1", nullable=False), - sa.Column("epics", sa.JSON(), nullable=False), - sa.Column("tasks", sa.JSON(), nullable=False), - sa.Column("steps", sa.JSON(), nullable=False), - sa.Column("iterations", sa.JSON(), nullable=False), - sa.Column("relevant_files", sa.JSON(), nullable=False), - sa.Column("modified_files", sa.JSON(), nullable=False), - sa.Column("run_command", sa.String(), nullable=True), - sa.ForeignKeyConstraint( - ["branch_id"], ["branches.id"], name=op.f("fk_project_states_branch_id_branches"), ondelete="CASCADE" - ), - sa.ForeignKeyConstraint( - ["prev_state_id"], - ["project_states.id"], - name=op.f("fk_project_states_prev_state_id_project_states"), - ondelete="CASCADE", - ), - sa.ForeignKeyConstraint( - ["specification_id"], ["specifications.id"], name=op.f("fk_project_states_specification_id_specifications") - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_project_states")), - sa.UniqueConstraint("branch_id", "step_index", name=op.f("uq_project_states_branch_id")), - sa.UniqueConstraint("prev_state_id", name=op.f("uq_project_states_prev_state_id")), - sqlite_autoincrement=True, - ) - op.create_table( - "files", - sa.Column("id", sa.Integer(), nullable=False), - sa.Column("project_state_id", sa.Uuid(), nullable=False), - sa.Column("content_id", sa.String(), nullable=False), - sa.Column("path", sa.String(), nullable=False), - sa.Column("meta", sa.JSON(), server_default="{}", nullable=False), - sa.ForeignKeyConstraint( - ["content_id"], ["file_contents.id"], name=op.f("fk_files_content_id_file_contents"), ondelete="RESTRICT" - ), - sa.ForeignKeyConstraint( - ["project_state_id"], - ["project_states.id"], - name=op.f("fk_files_project_state_id_project_states"), - ondelete="CASCADE", - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_files")), - sa.UniqueConstraint("project_state_id", "path", name=op.f("uq_files_project_state_id")), - ) - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table("files") - op.drop_table("project_states") - op.drop_table("branches") - op.drop_table("specifications") - op.drop_table("projects") - op.drop_table("file_contents") - # ### end Alembic commands ### diff --git a/core/db/migrations/versions/fd206d3095d0_store_request_input_exec_logs_to_db.py b/core/db/migrations/versions/fd206d3095d0_store_request_input_exec_logs_to_db.py deleted file mode 100644 index 3c70df90..00000000 --- a/core/db/migrations/versions/fd206d3095d0_store_request_input_exec_logs_to_db.py +++ /dev/null @@ -1,106 +0,0 @@ -"""store request input exec logs to db - -Revision ID: fd206d3095d0 -Revises: e7b54beadf8f -Create Date: 2024-05-09 08:25:10.698607 - -""" - -from typing import Sequence, Union - -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision: str = "fd206d3095d0" -down_revision: Union[str, None] = "e7b54beadf8f" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "exec_logs", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("branch_id", sa.Uuid(), nullable=False), - sa.Column("project_state_id", sa.Uuid(), nullable=True), - sa.Column("started_at", sa.DateTime(), nullable=False), - sa.Column("duration", sa.Float(), nullable=False), - sa.Column("cmd", sa.String(), nullable=False), - sa.Column("cwd", sa.String(), nullable=False), - sa.Column("env", sa.JSON(), nullable=False), - sa.Column("timeout", sa.Float(), nullable=True), - sa.Column("status_code", sa.Integer(), nullable=True), - sa.Column("stdout", sa.String(), nullable=False), - sa.Column("stderr", sa.String(), nullable=False), - sa.Column("analysis", sa.String(), nullable=False), - sa.Column("success", sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint( - ["branch_id"], ["branches.id"], name=op.f("fk_exec_logs_branch_id_branches"), ondelete="CASCADE" - ), - sa.ForeignKeyConstraint( - ["project_state_id"], - ["project_states.id"], - name=op.f("fk_exec_logs_project_state_id_project_states"), - ondelete="SET NULL", - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_exec_logs")), - ) - op.create_table( - "llm_requests", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("branch_id", sa.Uuid(), nullable=False), - sa.Column("project_state_id", sa.Uuid(), nullable=True), - sa.Column("started_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), - sa.Column("provider", sa.String(), nullable=False), - sa.Column("model", sa.String(), nullable=False), - sa.Column("temperature", sa.Float(), nullable=False), - sa.Column("messages", sa.JSON(), nullable=False), - sa.Column("response", sa.String(), nullable=True), - sa.Column("prompt_tokens", sa.Integer(), nullable=False), - sa.Column("completion_tokens", sa.Integer(), nullable=False), - sa.Column("duration", sa.Float(), nullable=False), - sa.Column("status", sa.String(), nullable=False), - sa.Column("error", sa.String(), nullable=True), - sa.ForeignKeyConstraint( - ["branch_id"], ["branches.id"], name=op.f("fk_llm_requests_branch_id_branches"), ondelete="CASCADE" - ), - sa.ForeignKeyConstraint( - ["project_state_id"], - ["project_states.id"], - name=op.f("fk_llm_requests_project_state_id_project_states"), - ondelete="SET NULL", - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_llm_requests")), - ) - op.create_table( - "user_inputs", - sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("branch_id", sa.Uuid(), nullable=False), - sa.Column("project_state_id", sa.Uuid(), nullable=True), - sa.Column("created_at", sa.DateTime(), server_default=sa.text("(CURRENT_TIMESTAMP)"), nullable=False), - sa.Column("question", sa.String(), nullable=False), - sa.Column("answer_text", sa.String(), nullable=True), - sa.Column("answer_button", sa.String(), nullable=True), - sa.Column("cancelled", sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint( - ["branch_id"], ["branches.id"], name=op.f("fk_user_inputs_branch_id_branches"), ondelete="CASCADE" - ), - sa.ForeignKeyConstraint( - ["project_state_id"], - ["project_states.id"], - name=op.f("fk_user_inputs_project_state_id_project_states"), - ondelete="SET NULL", - ), - sa.PrimaryKeyConstraint("id", name=op.f("pk_user_inputs")), - ) - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table("user_inputs") - op.drop_table("llm_requests") - op.drop_table("exec_logs") - # ### end Alembic commands ###