IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mensagempadrao'))
BEGIN

	CREATE TABLE [dbo].[mensagempadrao] (
		[id] int NOT NULL PRIMARY KEY,
		[conteudo] nvarchar(max) NULL,
		[titulo] nvarchar(255) NULL,
		[filter] nvarchar(max) NULL,
		[field] nvarchar(100) NULL);

END

IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mensagem'))
BEGIN

	CREATE TABLE [dbo].[mensagem] (
		[id] bigint  IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[conteudo] nvarchar(max) NULL,
		[titulo] nvarchar(255) NULL,
		[envio] datetime2 NULL,
		[lido] bit NULL,
		[idcliente] bigint NULL,
		[idusuario] int NULL,
		[idpadrao] int NULL);

END

IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Device'))
BEGIN

	CREATE TABLE [dbo].[Device] (
		[Id] bigint  IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[DeviceId] nvarchar(255) NULL,
		[IdCliente] bigint NULL);

END

IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'logconvite'))
BEGIN

	CREATE TABLE [dbo].[logconvite] (
		[id] int IDENTITY(1,1) NOT NULL,
		[idcliente] bigint  NULL,
		[email] nvarchar(250) NULL,
		[sent] bit  NULL,
		[idusuario] bigint  NULL,
		[data] datetime2  NULL);

END

IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'mensagemenviada'))
BEGIN

	CREATE TABLE [dbo].[mensagemenviada] (
		[id] int  IDENTITY(1,1) NOT NULL PRIMARY KEY,
		[resposta] nvarchar(max) NULL,
		[idusuario] int NULL,
		[idpadrao] int NULL,
		[data] datetime2 NULL);


END