Move the code over from private repository (#3)

This commit is contained in:
Kerem Yilmaz
2024-03-01 10:09:30 -08:00
committed by GitHub
parent 32dd6d92a5
commit 9eddb3d812
93 changed files with 16798 additions and 0 deletions

30
alembic/README.md Normal file
View File

@@ -0,0 +1,30 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- [Creating a new revision](#creating-a-new-revision)
- [Running migrations](#running-migrations)
- [Downgrading migrations](#downgrading-migrations)
- [Check your current alembic setup](#check-your-current-alembic-setup)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
# Creating a new revision
```
alembic revision --autogenerate -m "enter description here"
```
**Note:** Please read [What does Autogenerate Detect (and what does it not detect?)](https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect) and always make sure to review the generated revision file before running it.
# Running migrations
```
alembic upgrade head
```
# Downgrading migrations
```
alembic downgrade -1
```
# Check your current alembic setup
```
alembic current
```

81
alembic/env.py Normal file
View File

@@ -0,0 +1,81 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config, pool
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from skyvern.forge.sdk.db import models
target_metadata = models.Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
from skyvern.forge.sdk.settings_manager import SettingsManager
config.set_main_option("sqlalchemy.url", SettingsManager.get_settings().DATABASE_STRING)
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
print("Alembic mode: ", "offline" if context.is_offline_mode() else "online")
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

26
alembic/script.py.mako Normal file
View File

@@ -0,0 +1,26 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,284 @@
"""Create tables
Revision ID: 99423c1dec60
Revises:
Create Date: 2024-03-01 05:37:31.862957+00:00
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "99423c1dec60"
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(
"organizations",
sa.Column("organization_id", sa.String(), nullable=False),
sa.Column("organization_name", sa.String(), nullable=False),
sa.Column("webhook_callback_url", sa.UnicodeText(), nullable=True),
sa.Column("max_steps_per_run", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("organization_id"),
)
op.create_index(op.f("ix_organizations_organization_id"), "organizations", ["organization_id"], unique=False)
op.create_table(
"organization_auth_tokens",
sa.Column("id", sa.String(), nullable=False),
sa.Column("organization_id", sa.String(), nullable=False),
sa.Column("token_type", sa.Enum("api", name="organizationauthtokentype"), nullable=False),
sa.Column("token", sa.String(), nullable=False),
sa.Column("valid", sa.Boolean(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.Column("deleted_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_organization_auth_tokens_id"), "organization_auth_tokens", ["id"], unique=False)
op.create_index(
op.f("ix_organization_auth_tokens_organization_id"),
"organization_auth_tokens",
["organization_id"],
unique=False,
)
op.create_index(op.f("ix_organization_auth_tokens_token"), "organization_auth_tokens", ["token"], unique=False)
op.create_table(
"workflows",
sa.Column("workflow_id", sa.String(), nullable=False),
sa.Column("organization_id", sa.String(), nullable=True),
sa.Column("title", sa.String(), nullable=False),
sa.Column("description", sa.String(), nullable=True),
sa.Column("workflow_definition", sa.JSON(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.Column("deleted_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.PrimaryKeyConstraint("workflow_id"),
)
op.create_index(op.f("ix_workflows_workflow_id"), "workflows", ["workflow_id"], unique=False)
op.create_table(
"aws_secret_parameters",
sa.Column("aws_secret_parameter_id", sa.String(), nullable=False),
sa.Column("workflow_id", sa.String(), nullable=False),
sa.Column("key", sa.String(), nullable=False),
sa.Column("description", sa.String(), nullable=True),
sa.Column("aws_key", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.Column("deleted_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["workflow_id"],
["workflows.workflow_id"],
),
sa.PrimaryKeyConstraint("aws_secret_parameter_id"),
)
op.create_index(
op.f("ix_aws_secret_parameters_aws_secret_parameter_id"),
"aws_secret_parameters",
["aws_secret_parameter_id"],
unique=False,
)
op.create_index(
op.f("ix_aws_secret_parameters_workflow_id"), "aws_secret_parameters", ["workflow_id"], unique=False
)
op.create_table(
"workflow_parameters",
sa.Column("workflow_parameter_id", sa.String(), nullable=False),
sa.Column("workflow_parameter_type", sa.String(), nullable=False),
sa.Column("key", sa.String(), nullable=False),
sa.Column("description", sa.String(), nullable=True),
sa.Column("workflow_id", sa.String(), nullable=False),
sa.Column("default_value", sa.String(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.Column("deleted_at", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["workflow_id"],
["workflows.workflow_id"],
),
sa.PrimaryKeyConstraint("workflow_parameter_id"),
)
op.create_index(op.f("ix_workflow_parameters_workflow_id"), "workflow_parameters", ["workflow_id"], unique=False)
op.create_index(
op.f("ix_workflow_parameters_workflow_parameter_id"),
"workflow_parameters",
["workflow_parameter_id"],
unique=False,
)
op.create_table(
"workflow_runs",
sa.Column("workflow_run_id", sa.String(), nullable=False),
sa.Column("workflow_id", sa.String(), nullable=False),
sa.Column("status", sa.String(), nullable=False),
sa.Column(
"proxy_location",
sa.Enum("US_CA", "US_NY", "US_TX", "US_FL", "US_WA", "RESIDENTIAL", "NONE", name="proxylocation"),
nullable=True,
),
sa.Column("webhook_callback_url", sa.String(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["workflow_id"],
["workflows.workflow_id"],
),
sa.PrimaryKeyConstraint("workflow_run_id"),
)
op.create_index(op.f("ix_workflow_runs_workflow_run_id"), "workflow_runs", ["workflow_run_id"], unique=False)
op.create_table(
"tasks",
sa.Column("task_id", sa.String(), nullable=False),
sa.Column("organization_id", sa.String(), nullable=True),
sa.Column("status", sa.String(), nullable=True),
sa.Column("webhook_callback_url", sa.String(), nullable=True),
sa.Column("url", sa.String(), nullable=True),
sa.Column("navigation_goal", sa.String(), nullable=True),
sa.Column("data_extraction_goal", sa.String(), nullable=True),
sa.Column("navigation_payload", sa.JSON(), nullable=True),
sa.Column("extracted_information", sa.JSON(), nullable=True),
sa.Column("failure_reason", sa.String(), nullable=True),
sa.Column(
"proxy_location",
sa.Enum("US_CA", "US_NY", "US_TX", "US_FL", "US_WA", "RESIDENTIAL", "NONE", name="proxylocation"),
nullable=True,
),
sa.Column("extracted_information_schema", sa.JSON(), nullable=True),
sa.Column("workflow_run_id", sa.String(), nullable=True),
sa.Column("order", sa.Integer(), nullable=True),
sa.Column("retry", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.ForeignKeyConstraint(
["workflow_run_id"],
["workflow_runs.workflow_run_id"],
),
sa.PrimaryKeyConstraint("task_id"),
)
op.create_index(op.f("ix_tasks_task_id"), "tasks", ["task_id"], unique=False)
op.create_table(
"workflow_run_parameters",
sa.Column("workflow_run_id", sa.String(), nullable=False),
sa.Column("workflow_parameter_id", sa.String(), nullable=False),
sa.Column("value", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["workflow_parameter_id"],
["workflow_parameters.workflow_parameter_id"],
),
sa.ForeignKeyConstraint(
["workflow_run_id"],
["workflow_runs.workflow_run_id"],
),
sa.PrimaryKeyConstraint("workflow_run_id", "workflow_parameter_id"),
)
op.create_index(
op.f("ix_workflow_run_parameters_workflow_parameter_id"),
"workflow_run_parameters",
["workflow_parameter_id"],
unique=False,
)
op.create_index(
op.f("ix_workflow_run_parameters_workflow_run_id"), "workflow_run_parameters", ["workflow_run_id"], unique=False
)
op.create_table(
"steps",
sa.Column("step_id", sa.String(), nullable=False),
sa.Column("organization_id", sa.String(), nullable=True),
sa.Column("task_id", sa.String(), nullable=True),
sa.Column("status", sa.String(), nullable=True),
sa.Column("output", sa.JSON(), nullable=True),
sa.Column("order", sa.Integer(), nullable=True),
sa.Column("is_last", sa.Boolean(), nullable=True),
sa.Column("retry_index", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.Column("input_token_count", sa.Integer(), nullable=True),
sa.Column("output_token_count", sa.Integer(), nullable=True),
sa.Column("step_cost", sa.Numeric(), nullable=True),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.ForeignKeyConstraint(
["task_id"],
["tasks.task_id"],
),
sa.PrimaryKeyConstraint("step_id"),
)
op.create_index(op.f("ix_steps_step_id"), "steps", ["step_id"], unique=False)
op.create_table(
"artifacts",
sa.Column("artifact_id", sa.String(), nullable=False),
sa.Column("organization_id", sa.String(), nullable=True),
sa.Column("task_id", sa.String(), nullable=True),
sa.Column("step_id", sa.String(), nullable=True),
sa.Column("artifact_type", sa.String(), nullable=True),
sa.Column("uri", sa.String(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("modified_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.organization_id"],
),
sa.ForeignKeyConstraint(
["step_id"],
["steps.step_id"],
),
sa.ForeignKeyConstraint(
["task_id"],
["tasks.task_id"],
),
sa.PrimaryKeyConstraint("artifact_id"),
)
op.create_index(op.f("ix_artifacts_artifact_id"), "artifacts", ["artifact_id"], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_artifacts_artifact_id"), table_name="artifacts")
op.drop_table("artifacts")
op.drop_index(op.f("ix_steps_step_id"), table_name="steps")
op.drop_table("steps")
op.drop_index(op.f("ix_workflow_run_parameters_workflow_run_id"), table_name="workflow_run_parameters")
op.drop_index(op.f("ix_workflow_run_parameters_workflow_parameter_id"), table_name="workflow_run_parameters")
op.drop_table("workflow_run_parameters")
op.drop_index(op.f("ix_tasks_task_id"), table_name="tasks")
op.drop_table("tasks")
op.drop_index(op.f("ix_workflow_runs_workflow_run_id"), table_name="workflow_runs")
op.drop_table("workflow_runs")
op.drop_index(op.f("ix_workflow_parameters_workflow_parameter_id"), table_name="workflow_parameters")
op.drop_index(op.f("ix_workflow_parameters_workflow_id"), table_name="workflow_parameters")
op.drop_table("workflow_parameters")
op.drop_index(op.f("ix_aws_secret_parameters_workflow_id"), table_name="aws_secret_parameters")
op.drop_index(op.f("ix_aws_secret_parameters_aws_secret_parameter_id"), table_name="aws_secret_parameters")
op.drop_table("aws_secret_parameters")
op.drop_index(op.f("ix_workflows_workflow_id"), table_name="workflows")
op.drop_table("workflows")
op.drop_index(op.f("ix_organization_auth_tokens_token"), table_name="organization_auth_tokens")
op.drop_index(op.f("ix_organization_auth_tokens_organization_id"), table_name="organization_auth_tokens")
op.drop_index(op.f("ix_organization_auth_tokens_id"), table_name="organization_auth_tokens")
op.drop_table("organization_auth_tokens")
op.drop_index(op.f("ix_organizations_organization_id"), table_name="organizations")
op.drop_table("organizations")
# ### end Alembic commands ###