Skip to content

Commit

Permalink
added skip creating table if already exsist
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluder-Paradyne committed Jun 1, 2023
1 parent f46cfdf commit af7c5b3
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 94 deletions.
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# output_encoding = utf-8


sqlalchemy.url = postgresql://superagi:password@super__postgres:5432/super_agi_main
sqlalchemy.url = postgresql://superagi:password@localhost:5432/super_agi_main
; sqlalchemy.url = driver://user:pass@localhost/dbname


Expand Down
202 changes: 109 additions & 93 deletions migrations/versions/44b0d6f2d1b3_init_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,102 +15,118 @@
branch_labels = None
depends_on = None

from sqlalchemy.engine.reflection import Inspector

conn = op.get_bind()
inspector = Inspector.from_engine(conn)
tables = inspector.get_table_names()
print(tables)

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('agent_configurations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('key', sa.String(), nullable=True),
sa.Column('value', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('agent_execution_feeds',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('agent_execution_id', sa.Integer(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('feed', sa.Text(), nullable=True),
sa.Column('role', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('agent_executions',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('status', sa.String(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('last_execution_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('agents',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('budgets',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('budget', sa.Float(), nullable=True),
sa.Column('cycle', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('organisations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('projects',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('organisation_id', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('tool_configs',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('key', sa.String(), nullable=True),
sa.Column('value', sa.String(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('tools',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('folder_name', sa.String(), nullable=True),
sa.Column('class_name', sa.String(), nullable=True),
sa.Column('file_name', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('users',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
sa.Column('organisation_id', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
if 'agent_configurations' not in tables:
op.create_table('agent_configurations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('key', sa.String(), nullable=True),
sa.Column('value', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'agent_execution_feeds' not in tables:
op.create_table('agent_execution_feeds',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('agent_execution_id', sa.Integer(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('feed', sa.Text(), nullable=True),
sa.Column('role', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'agent_executions' not in tables:
op.create_table('agent_executions',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('status', sa.String(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.Column('last_execution_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'agents' not in tables:
op.create_table('agents',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'budgets' not in tables:
op.create_table('budgets',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('budget', sa.Float(), nullable=True),
sa.Column('cycle', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'organisations' not in tables:
op.create_table('organisations',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'projects' not in tables:
op.create_table('projects',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('organisation_id', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'tool_configs' not in tables:
op.create_table('tool_configs',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('key', sa.String(), nullable=True),
sa.Column('value', sa.String(), nullable=True),
sa.Column('agent_id', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'tools' not in tables:
op.create_table('tools',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('folder_name', sa.String(), nullable=True),
sa.Column('class_name', sa.String(), nullable=True),
sa.Column('file_name', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
if 'users' not in tables:
op.create_table('users',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
sa.Column('organisation_id', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
# ### end Alembic commands ###


Expand Down

0 comments on commit af7c5b3

Please sign in to comment.