/ migrations / versions / 043_project_templates.py
043_project_templates.py
 1  """Project template library — reusable project snapshots.
 2  
 3  Adds the ``project_templates`` table that lets users publish a
 4  project's config (system prompt + options + Blockly workspace) as a
 5  clonable "starter pack" with three-tier visibility (private / team /
 6  public). Decouples sharing from the live project so an admin can share
 7  a "Customer Support Bot" template without making the underlying
 8  project public.
 9  """
10  import sqlalchemy as sa
11  from alembic import op
12  
13  
14  revision = '043'
15  down_revision = '042'
16  branch_labels = None
17  depends_on = None
18  
19  
20  def upgrade():
21      try:
22          op.create_table(
23              'project_templates',
24              sa.Column('id', sa.Integer(), primary_key=True, index=True),
25              sa.Column('name', sa.String(255), nullable=False, index=True),
26              sa.Column('description', sa.Text(), nullable=True),
27              sa.Column('project_type', sa.String(20), nullable=False),
28              sa.Column('suggested_llm', sa.String(255), nullable=True),
29              sa.Column('suggested_embeddings', sa.String(255), nullable=True),
30              sa.Column('system_prompt', sa.Text(), nullable=True),
31              sa.Column('options_json', sa.Text(), nullable=True),
32              sa.Column('blockly_workspace', sa.Text(), nullable=True),
33              sa.Column('visibility', sa.String(20), nullable=False, server_default='private'),
34              sa.Column('creator_id', sa.Integer(), sa.ForeignKey('users.id', ondelete='SET NULL'), nullable=True),
35              sa.Column('team_id', sa.Integer(), sa.ForeignKey('teams.id', ondelete='SET NULL'), nullable=True),
36              sa.Column('created_at', sa.DateTime(), nullable=False),
37              sa.Column('use_count', sa.Integer(), nullable=False, server_default='0'),
38          )
39      except Exception:
40          # Already created on a partial re-run.
41          pass
42  
43  
44  def downgrade():
45      try:
46          op.drop_table('project_templates')
47      except Exception:
48          pass