Commit 3b34d800 authored by Cedric Abunar's avatar Cedric Abunar

refactor sqlalchemy models

parent 9d784d4c
......@@ -15,20 +15,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column
from sqlalchemy.schema import Column, UniqueConstraint, Index
from sqlalchemy.types import Integer, String, TEXT
from xivo_dao.helpers.db_manager import Base
class AccessWebService(Base):
__tablename__ = 'accesswebservice'
__table_args__ = (
UniqueConstraint('name'),
Index('accesswebservice__idx__disable', 'disable'),
Index('accesswebservice__idx__host', 'host'),
Index('accesswebservice__idx__login', 'login'),
Index('accesswebservice__idx__passwd', 'passwd')
)
id = Column(Integer, primary_key=True)
name = Column(String(64), nullable=False)
name = Column(String(64), nullable=False, server_default='')
login = Column(String(64))
passwd = Column(String(64))
host = Column(String(255))
obj = Column(TEXT, nullable=False)
disable = Column(Integer, nullable=False, default=0)
disable = Column(Integer, nullable=False, server_default='0')
description = Column(TEXT, nullable=False)
......@@ -15,14 +15,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.schema import Column, UniqueConstraint
from sqlalchemy.types import Integer, String, DateTime
from sqlalchemy.sql import func
from xivo_dao.helpers.db_manager import Base
class AgentLoginStatus(Base):
__tablename__ = 'agent_login_status'
__table_args__ = (
UniqueConstraint('extension', 'context'),
UniqueConstraint('interface')
)
agent_id = Column(Integer, primary_key=True)
agent_number = Column(String(40), nullable=False)
......@@ -30,4 +36,4 @@ class AgentLoginStatus(Base):
context = Column(String(80), nullable=False)
interface = Column(String(128), nullable=False, unique=True)
state_interface = Column(String(128), nullable=False)
login_at = Column(DateTime, nullable=False, default=func.now())
login_at = Column(DateTime, nullable=False, server_default=func.now())
......@@ -15,12 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
class AgentMembershipStatus(Base):
__tablename__ = 'agent_membership_status'
agent_id = Column(Integer, primary_key=True)
......
......@@ -15,12 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
class AgentFeatures(Base):
__tablename__ = 'agentfeatures'
id = Column(Integer, primary_key=True)
......@@ -33,5 +35,5 @@ class AgentFeatures(Base):
language = Column(String(20), nullable=False)
autologoff = Column(Integer)
group = Column(String(255))
description = Column(Text)
description = Column(Text, nullable=False)
preprocess_subroutine = Column(String(40))
......@@ -15,10 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer
from xivo_dao.helpers.db_manager import Base
class AgentQueueSkill(Base):
......@@ -26,4 +27,4 @@ class AgentQueueSkill(Base):
agentid = Column(Integer, primary_key=True, nullable=False)
skillid = Column(Integer, primary_key=True, nullable=False)
weight = Column(Integer, default=0, nullable=False)
weight = Column(Integer, nullable=False, server_default='0')
......@@ -17,13 +17,15 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import DateTime, Integer, String, Boolean, Interval
from xivo_dao.helpers.db_manager import Base
class CallLog(Base):
__tablename__ = 'call_log'
id = Column(Integer, primary_key=True)
id = Column(Integer, nullable=False, primary_key=True)
date = Column(DateTime, nullable=False)
source_name = Column(String(255))
source_exten = Column(String(255))
......
......@@ -15,20 +15,24 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column
from sqlalchemy.schema import Column, Index
from sqlalchemy.types import Integer, String, Enum, Text
from xivo_dao.helpers.db_manager import Base, Type
from xivo_dao.helpers.db_manager import Base
class Callfilter(Base):
__tablename__ = 'callfilter'
__table_args__ = (
Index('callfilter__uidx__name', 'name'),
)
id = Column(Integer, primary_key=True)
id = Column(Integer, nullable=False, primary_key=True)
name = Column(String(128), nullable=False, server_default='')
type = Column(Enum('bosssecretary',
name='callfilter_type',
metadata=Type.metadata),
metadata=Base.metadata),
nullable=False)
bosssecretary = Column(Enum('bossfirst-serial',
'bossfirst-simult',
......@@ -36,12 +40,12 @@ class Callfilter(Base):
'secretary-simult',
'all',
name='callfilter_bosssecretary',
metadata=Type.metadata),
metadata=Base.metadata),
nullable=False)
callfrom = Column(Enum('internal', 'external', 'all',
name='callfilter_callfrom',
metadata=Type.metadata),
metadata=Base.metadata),
nullable=False)
ringseconds = Column(Integer, nullable=False, default=0)
commented = Column(Integer, nullable=False, default=0)
ringseconds = Column(Integer, nullable=False, server_default='0')
commented = Column(Integer, nullable=False, server_default='0')
description = Column(Text, nullable=False)
......@@ -15,26 +15,30 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.schema import Column, ForeignKey, UniqueConstraint
from sqlalchemy.types import Integer, String, Enum
from xivo_dao.helpers.db_manager import Base, Type
from xivo_dao.helpers.db_manager import Base
class Callfiltermember(Base):
__tablename__ = 'callfiltermember'
__table_args__ = (
UniqueConstraint('callfilterid', 'type', 'typeval'),
)
id = Column(Integer, primary_key=True)
callfilterid = Column(Integer, ForeignKey('callfilter.id'))
type = Column(Enum('user',
name='callfiltermember_type',
metadata=Type.metadata),
metadata=Base.metadata),
nullable=False)
typeval = Column(String(128), nullable=False, default=0)
ringseconds = Column(Integer, nullable=False, default=0)
priority = Column(Integer, nullable=False, default=0)
typeval = Column(String(128), nullable=False, server_default='0')
ringseconds = Column(Integer, nullable=False, server_default='0')
priority = Column(Integer, nullable=False, server_default='0')
bstype = Column(Enum('boss', 'secretary',
name='generic_bsfilter',
metadata=Type.metadata),
metadata=Base.metadata),
nullable=False)
active = Column(Integer, nullable=False, default=0)
active = Column(Integer, nullable=False, server_default='0')
......@@ -16,17 +16,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.orm import relationship
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.schema import Column, ForeignKey, Index
from sqlalchemy.types import DateTime, Integer, String
from xivo_dao.helpers.db_manager import Base
from xivo_dao.alchemy.call_log import CallLog
from xivo_dao.helpers.db_manager import Base
class CEL(Base):
__tablename__ = 'cel'
__table_args__ = (
Index('cel__idx__call_log_id', 'call_log_id'),
Index('cel__idx__eventtime', 'eventtime'),
Index('cel__idx__linkedid', 'linkedid'),
Index('cel__idx__uniqueid', 'uniqueid'),
)
id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, nullable=False)
eventtype = Column(String(30), nullable=False)
eventtime = Column(DateTime, nullable=False)
userdeftype = Column(String(255), nullable=False)
......@@ -48,4 +54,5 @@ class CEL(Base):
userfield = Column(String(255), nullable=False)
peer = Column(String(80), nullable=False)
call_log_id = Column(Integer, ForeignKey('call_log.id'))
call_log = relationship(CallLog, backref='cels')
call_log = relationship('CallLog', foreign_keys=call_log_id, backref='cels')
......@@ -15,19 +15,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
class Context(Base):
__tablename__ = 'context'
name = Column(String(39), primary_key=True)
displayname = Column(String(128), nullable=False, default='')
displayname = Column(String(128), nullable=False, server_default='')
entity = Column(String(64))
contexttype = Column(String(20), nullable=False, default='internal')
commented = Column(Integer, nullable=False, default=0)
contexttype = Column(String(20), nullable=False, server_default='internal')
commented = Column(Integer, nullable=False, server_default='0')
description = Column(Text, nullable=False)
......@@ -15,11 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
class ContextInclude(Base):
......@@ -27,4 +27,4 @@ class ContextInclude(Base):
context = Column(String(39), primary_key=True)
include = Column(String(39), primary_key=True)
priority = Column(Integer, nullable=False, default=0)
priority = Column(Integer, nullable=False, server_default='0')
......@@ -17,6 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import String
from xivo_dao.helpers.db_manager import Base
......
......@@ -15,11 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base, Type
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Enum
from xivo_dao.helpers.db_manager import Base
class ContextNumbers(Base):
......@@ -28,8 +28,8 @@ class ContextNumbers(Base):
context = Column(String(39), primary_key=True)
type = Column(Enum('user', 'group', 'queue', 'meetme', 'incall',
name='contextnumbers_type',
metadata=Type.metadata),
metadata=Base.metadata),
primary_key=True)
numberbeg = Column(String(16), default=0, primary_key=True)
numberend = Column(String(16), default=0, primary_key=True)
didlength = Column(Integer, nullable=False, default=0)
numberbeg = Column(String(16), server_default='0', primary_key=True)
numberend = Column(String(16), server_default='0', primary_key=True)
didlength = Column(Integer, nullable=False, server_default='0')
......@@ -15,11 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.helpers.db_manager import Base
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
class ContextType(Base):
......
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +25,7 @@ class CtiContexts(Base):
__tablename__ = 'cticontexts'
id = Column(Integer, Sequence('cticontexts_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(50))
directories = Column(Text, nullable=False)
display = Column(Text, nullable=False)
......
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String, Text
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +25,7 @@ class CtiDisplays(Base):
__tablename__ = 'ctidisplays'
id = Column(Integer, Sequence('ctidisplays_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(50))
data = Column(Text, nullable=False)
description = Column(Text)
......
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,5 +25,5 @@ class CtiPreference(Base):
__tablename__ = 'cti_preference'
id = Column(Integer, Sequence('cti_preference_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
option = Column(String(255), nullable=False)
......@@ -15,8 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, ForeignKey, Sequence
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relationship
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +26,10 @@ class CtiProfile(Base):
__tablename__ = 'cti_profile'
id = Column(Integer, Sequence('cti_profile_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
presence_id = Column(Integer, ForeignKey("ctipresences.id"))
phonehints_id = Column(Integer, ForeignKey("ctiphonehintsgroup.id"))
ctipresences = relationship("CtiPresences", foreign_keys=presence_id)
ctiphonehintsgroup = relationship("CtiPhoneHintsGroup", foreign_keys=phonehints_id)
......@@ -17,6 +17,8 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, String
from sqlalchemy.orm import relationship
from xivo_dao.helpers.db_manager import Base
......@@ -27,3 +29,6 @@ class CtiProfilePreference(Base):
profile_id = Column(Integer, ForeignKey('cti_profile.id'), primary_key=True)
preference_id = Column(Integer, ForeignKey("cti_preference.id"), primary_key=True)
value = Column(String(255), nullable=False)
cti_profile = relationship("CtiProfile", foreign_keys=profile_id)
cti_preference = relationship("CtiPreference", foreign_keys=preference_id)
......@@ -17,6 +17,8 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer
from sqlalchemy.orm import relationship
from xivo_dao.helpers.db_manager import Base
......@@ -26,3 +28,6 @@ class CtiProfileService(Base):
profile_id = Column(Integer, ForeignKey('cti_profile.id'), primary_key=True)
service_id = Column(Integer, ForeignKey("cti_service.id"), primary_key=True)
cti_profile = relationship("CtiProfile", foreign_keys=profile_id)
cti_service = relationship("CtiService", foreign_keys=service_id)
......@@ -17,6 +17,8 @@
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer, Boolean
from sqlalchemy.orm import relationship
from xivo_dao.helpers.db_manager import Base
......@@ -27,8 +29,12 @@ class CtiProfileXlet(Base):
xlet_id = Column(Integer, ForeignKey("cti_xlet.id"), primary_key=True)
profile_id = Column(Integer, ForeignKey('cti_profile.id'), primary_key=True)
layout_id = Column(Integer, ForeignKey("cti_xlet_layout.id"))
closable = Column(Boolean, default=True)
movable = Column(Boolean, default=True)
floating = Column(Boolean, default=True)
scrollable = Column(Boolean, default=True)
closable = Column(Boolean, server_default='True')
movable = Column(Boolean, server_default='True')
floating = Column(Boolean, server_default='True')
scrollable = Column(Boolean, server_default='True')
order = Column(Integer)
cti_xlet = relationship("CtiXlet", foreign_keys=xlet_id)
cti_profile = relationship("CtiProfile", foreign_keys=profile_id)
cti_xlet_layout = relationship("CtiXletLayout", foreign_keys=layout_id)
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,5 +25,5 @@ class CtiService(Base):
__tablename__ = 'cti_service'
id = Column(Integer, Sequence('cti_service_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
key = Column(String(255), nullable=False)
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,5 +25,5 @@ class CtiXlet(Base):
__tablename__ = 'cti_xlet'
id = Column(Integer, Sequence('cti_xlet_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
plugin_name = Column(String(40), nullable=False)
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,5 +25,5 @@ class CtiXletLayout(Base):
__tablename__ = 'cti_xlet_layout'
id = Column(Integer, Sequence('cti_xlet_layout_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, Text, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +25,7 @@ class CtiDirectories(Base):
__tablename__ = 'ctidirectories'
id = Column(Integer, Sequence('ctidirectories_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(255))
uri = Column(String(255))
delimiter = Column(String(20))
......
......@@ -17,6 +17,7 @@
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +25,7 @@ class CtiMain(Base):
__tablename__ = 'ctimain'
id = Column(Integer, Sequence('ctimain_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
commandset = Column(String(20))
ami_ip = Column(String(16))
ami_port = Column(Integer)
......@@ -32,16 +33,16 @@ class CtiMain(Base):
ami_password = Column(String(64))
cti_ip = Column(String(16))
cti_port = Column(Integer)
cti_active = Column(Integer, nullable=False, default=1)
cti_active = Column(Integer, nullable=False, server_default='1')
ctis_ip = Column(String(16))
ctis_port = Column(Integer)
ctis_active = Column(Integer, nullable=False, default=1)
ctis_active = Column(Integer, nullable=False, server_default='1')
webi_ip = Column(String(16))
webi_port = Column(Integer)
webi_active = Column(Integer, nullable=False, default=1)
webi_active = Column(Integer, nullable=False, server_default='1')
info_ip = Column(String(16))
info_port = Column(Integer)
info_active = Column(Integer, nullable=False, default=1)
info_active = Column(Integer, nullable=False, server_default='1')
tlscertfile = Column(String(128))
tlsprivkeyfile = Column(String(128))
socket_timeout = Column(Integer)
......
......@@ -17,6 +17,7 @@
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......
......@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from sqlalchemy.schema import Column, Sequence
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
from xivo_dao.helpers.db_manager import Base
......@@ -24,7 +25,7 @@ class CtiPhoneHintsGroup(Base):
__tablename__ = 'ctiphonehintsgroup'
id = Column(Integer, Sequence('ctiphonehintsgroup_id_seq'), primary_key=True)
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)