mirror of https://github.com/apache/superset.git
Add cascade delete to the 1 to composite relationships. (#1295)
This commit is contained in:
parent
9012b11101
commit
19677438c2
|
@ -40,7 +40,7 @@ from sqlalchemy import (
|
|||
)
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
from sqlalchemy.sql import table, literal_column, text, column
|
||||
from sqlalchemy.sql.expression import ColumnClause, TextAsFrom
|
||||
from sqlalchemy_utils import EncryptedType
|
||||
|
@ -679,7 +679,9 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
|||
user_id = Column(Integer, ForeignKey('ab_user.id'))
|
||||
owner = relationship('User', backref='tables', foreign_keys=[user_id])
|
||||
database = relationship(
|
||||
'Database', backref='tables', foreign_keys=[database_id])
|
||||
'Database',
|
||||
backref=backref('tables', cascade='all, delete-orphan'),
|
||||
foreign_keys=[database_id])
|
||||
offset = Column(Integer, default=0)
|
||||
cache_timeout = Column(Integer)
|
||||
schema = Column(String(255))
|
||||
|
@ -1069,7 +1071,9 @@ class SqlMetric(Model, AuditMixinNullable):
|
|||
metric_type = Column(String(32))
|
||||
table_id = Column(Integer, ForeignKey('tables.id'))
|
||||
table = relationship(
|
||||
'SqlaTable', backref='metrics', foreign_keys=[table_id])
|
||||
'SqlaTable',
|
||||
backref=backref('metrics', cascade='all, delete-orphan'),
|
||||
foreign_keys=[table_id])
|
||||
expression = Column(Text)
|
||||
description = Column(Text)
|
||||
is_restricted = Column(Boolean, default=False, nullable=True)
|
||||
|
@ -1096,7 +1100,9 @@ class TableColumn(Model, AuditMixinNullable):
|
|||
id = Column(Integer, primary_key=True)
|
||||
table_id = Column(Integer, ForeignKey('tables.id'))
|
||||
table = relationship(
|
||||
'SqlaTable', backref='columns', foreign_keys=[table_id])
|
||||
'SqlaTable',
|
||||
backref=backref('columns', cascade='all, delete-orphan'),
|
||||
foreign_keys=[table_id])
|
||||
column_name = Column(String(255))
|
||||
verbose_name = Column(String(1024))
|
||||
is_dttm = Column(Boolean, default=False)
|
||||
|
@ -1242,7 +1248,10 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable):
|
|||
description = Column(Text)
|
||||
default_endpoint = Column(Text)
|
||||
user_id = Column(Integer, ForeignKey('ab_user.id'))
|
||||
owner = relationship('User', backref='datasources', foreign_keys=[user_id])
|
||||
owner = relationship(
|
||||
'User',
|
||||
backref=backref('datasources', cascade='all, delete-orphan'),
|
||||
foreign_keys=[user_id])
|
||||
cluster_name = Column(
|
||||
String(250), ForeignKey('clusters.cluster_name'))
|
||||
cluster = relationship(
|
||||
|
@ -1799,8 +1808,10 @@ class DruidMetric(Model, AuditMixinNullable):
|
|||
String(255),
|
||||
ForeignKey('datasources.datasource_name'))
|
||||
# Setting enable_typechecks=False disables polymorphic inheritance.
|
||||
datasource = relationship('DruidDatasource', backref='metrics',
|
||||
enable_typechecks=False)
|
||||
datasource = relationship(
|
||||
'DruidDatasource',
|
||||
backref=backref('metrics', cascade='all, delete-orphan'),
|
||||
enable_typechecks=False)
|
||||
json = Column(Text)
|
||||
description = Column(Text)
|
||||
is_restricted = Column(Boolean, default=False, nullable=True)
|
||||
|
@ -1833,8 +1844,10 @@ class DruidColumn(Model, AuditMixinNullable):
|
|||
String(255),
|
||||
ForeignKey('datasources.datasource_name'))
|
||||
# Setting enable_typechecks=False disables polymorphic inheritance.
|
||||
datasource = relationship('DruidDatasource', backref='columns',
|
||||
enable_typechecks=False)
|
||||
datasource = relationship(
|
||||
'DruidDatasource',
|
||||
backref=backref('columns', cascade='all, delete-orphan'),
|
||||
enable_typechecks=False)
|
||||
column_name = Column(String(255))
|
||||
is_active = Column(Boolean, default=True)
|
||||
type = Column(String(32))
|
||||
|
@ -2006,7 +2019,10 @@ class Query(Model):
|
|||
|
||||
database = relationship(
|
||||
'Database', foreign_keys=[database_id], backref='queries')
|
||||
user = relationship('User', backref='queries', foreign_keys=[user_id])
|
||||
user = relationship(
|
||||
'User',
|
||||
backref=backref('queries', cascade='all, delete-orphan'),
|
||||
foreign_keys=[user_id])
|
||||
|
||||
__table_args__ = (
|
||||
sqla.Index('ti_user_id_changed_on', user_id, changed_on),
|
||||
|
|
Loading…
Reference in New Issue