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