Skip to content

Commit

Permalink
Fix migration for make creator owners (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShengyaoQian authored and mistercrunch committed Oct 20, 2016
1 parent 458651f commit ece69fb
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions caravel/migrations/versions/27ae655e4247_make_creator_owners.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,43 @@
from alembic import op
from caravel import db
from sqlalchemy.ext.declarative import declarative_base
from flask_appbuilder.models.mixins import AuditMixin
from sqlalchemy.orm import relationship
from flask_appbuilder import Model
from sqlalchemy import (
Column, Integer, ForeignKey, Table)

Base = declarative_base()

class User(Base):
"""Declarative class to do query in upgrade"""
__tablename__ = 'ab_user'
id = Column(Integer, primary_key=True)

slice_user = Table('slice_user', Base.metadata,
Column('id', Integer, primary_key=True),
Column('user_id', Integer, ForeignKey('ab_user.id')),
Column('slice_id', Integer, ForeignKey('slices.id'))
)

class Slice(Base):
dashboard_user = Table(
'dashboard_user', Base.metadata,
Column('id', Integer, primary_key=True),
Column('user_id', Integer, ForeignKey('ab_user.id')),
Column('dashboard_id', Integer, ForeignKey('dashboards.id'))
)

class Slice(Base, AuditMixin):
"""Declarative class to do query in upgrade"""
__tablename__ = 'slices'
id = Column(Integer, primary_key=True)
owners = relationship("User", secondary=slice_user)


class Dashboard(Base):
class Dashboard(Base, AuditMixin):
"""Declarative class to do query in upgrade"""
__tablename__ = 'dashboards'
id = Column(Integer, primary_key=True)

owners = relationship("User", secondary=dashboard_user)

def upgrade():
bind = op.get_bind()
Expand Down

0 comments on commit ece69fb

Please sign in to comment.