﻿--Migration
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK]
    ADD [C_ISIKTESZKOZOKETLGALABB40HASZ] CHAR (1) DEFAULT ('T') NOT NULL,
        [C_ISINFORMATKEPISMRENDELKEZIK]  CHAR (1) DEFAULT ('T') NOT NULL,
        [C_ISINTERNETETOKTCELRAHASZNAL]  CHAR (1) DEFAULT ('T') NOT NULL,
        [C_KEPESITESTIPUSID]             INT      NULL;


GO
PRINT N'Creating Index [dbo].[T_MUNKAUGYIADATOK].[NCI_MunkaugyiAdatok_IntezmenyId_TanevId_KepesitesTipusId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_MunkaugyiAdatok_IntezmenyId_TanevId_KepesitesTipusId]
    ON [dbo].[T_MUNKAUGYIADATOK]([C_INTEZMENYID] ASC, [C_TANEVID] ASC, [C_KEPESITESTIPUSID] ASC);


GO
PRINT N'Altering Table [dbo].[T_TANULO]...';


GO
ALTER TABLE [dbo].[T_TANULO]
    ADD [C_ISEGESZNAPOSISKOKTRESZESUL]   CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISKIEMELTENTEHETSEGES]        CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISSZABOKYADOLFSZAKKEPODRESZE] CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISSZAMITOGEPETOKTCELRAHASZNA] CHAR (1) DEFAULT ('T') NOT NULL;


GO
PRINT N'Altering Table [dbo].[T_TANULOTANUGYIADATOK]...';


GO
ALTER TABLE [dbo].[T_TANULOTANUGYIADATOK]
    ADD [C_ISEGESZNAPOSISKOKTRESZESUL]   CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISKIEMELTENTEHETSEGES]        CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISSZABOKYADOLFSZAKKEPODRESZE] CHAR (1) DEFAULT ('F') NOT NULL,
        [C_ISSZAMITOGEPETOKTCELRAHASZNA] CHAR (1) DEFAULT ('T') NOT NULL;


GO
PRINT N'Creating Table [dbo].[T_KEPESITESTIPUS]...';


GO
CREATE TABLE [dbo].[T_KEPESITESTIPUS] (
    [ID]                   INT      NOT NULL,
    [C_ALINTEZMENYID]      INT      NOT NULL,
    [C_ALTANEVID]          INT      NOT NULL,
    [TOROLT]               CHAR (1) NOT NULL,
    [SERIAL]               INT      NOT NULL,
    [LASTCHANGED]          DATETIME NOT NULL,
    [CREATED]              DATETIME NOT NULL,
    [MODIFIER]             INT      NULL,
    [CREATOR]              INT      NULL,
    [ELOZOTANEVIREKORDID]  INT      NULL,
    [ELOZOTANEVIREKORDIDA] INT      NULL,
    CONSTRAINT [PK_KepesitesTipus] PRIMARY KEY CLUSTERED ([ID] ASC, [C_ALINTEZMENYID] ASC, [C_ALTANEVID] ASC)
);


GO
PRINT N'Creating Index [dbo].[T_KEPESITESTIPUS].[NCI_KepesitesTipus_AlIntezmenyId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_KepesitesTipus_AlIntezmenyId]
    ON [dbo].[T_KEPESITESTIPUS]([C_ALINTEZMENYID] ASC);


GO
PRINT N'Creating Index [dbo].[T_KEPESITESTIPUS].[NCI_KepesitesTipus_AlTanevId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_KepesitesTipus_AlTanevId]
    ON [dbo].[T_KEPESITESTIPUS]([C_ALTANEVID] ASC);


GO
PRINT N'Creating Default Constraint unnamed constraint on [dbo].[T_KEPESITESTIPUS]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS]
    ADD DEFAULT (getdate()) FOR [CREATED];


GO
PRINT N'Creating Default Constraint unnamed constraint on [dbo].[T_KEPESITESTIPUS]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS]
    ADD DEFAULT ('F') FOR [TOROLT];


GO
PRINT N'Creating Default Constraint unnamed constraint on [dbo].[T_KEPESITESTIPUS]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS]
    ADD DEFAULT ((0)) FOR [SERIAL];


GO
PRINT N'Creating Default Constraint unnamed constraint on [dbo].[T_KEPESITESTIPUS]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS]
    ADD DEFAULT (getdate()) FOR [LASTCHANGED];


GO
PRINT N'Creating Foreign Key [dbo].[FK_KepesitesTipus_AlIntezmenyId_REF_Intezmeny]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_KepesitesTipus_AlIntezmenyId_REF_Intezmeny] FOREIGN KEY ([C_ALINTEZMENYID]) REFERENCES [dbo].[T_INTEZMENY] ([ID]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_KepesitesTipus_AlTanevId_REF_Tanev]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_KepesitesTipus_AlTanevId_REF_Tanev] FOREIGN KEY ([C_ALTANEVID]) REFERENCES [dbo].[T_TANEV] ([ID]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_KepesitesTipus_Id_AlintezmenyId_AltanevId_REF_DictionaryItemBase]...';


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH NOCHECK
    ADD CONSTRAINT [FK_KepesitesTipus_Id_AlintezmenyId_AltanevId_REF_DictionaryItemBase] FOREIGN KEY ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) REFERENCES [dbo].[T_DICTIONARYITEMBASE] ([ID], [C_INTEZMENYID], [C_TANEVID]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_MunkaugyiAdatok_KepesitesTipusId_IntezmenyId_TanevId_REF_KepesitesTipus]...';


GO
ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] WITH NOCHECK
    ADD CONSTRAINT [FK_MunkaugyiAdatok_KepesitesTipusId_IntezmenyId_TanevId_REF_KepesitesTipus] FOREIGN KEY ([C_KEPESITESTIPUSID], [C_INTEZMENYID], [C_TANEVID]) REFERENCES [dbo].[T_KEPESITESTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]);


GO

GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord egyedi azonosítója, generált IDENTITY(1, 1) (kivéve altáblák esetén, ahol a főtábla ID-ját kapja)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'ID';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[C_ALINTEZMENYID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'Az intézmény ID-ja, amihez a rekord tartozik (altábla esetén)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'C_ALINTEZMENYID';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[C_ALTANEVID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A tanév ID-ja, amihez a rekord tartozik (altábla esetén)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'C_ALTANEVID';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[TOROLT].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord logikai töröltségét jelző flag', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'TOROLT';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[SERIAL].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'Minden C# kódból történő módosítás esetén eggyel nő az értéke. Hogy párhuzamos módosítás esetnán ne íródjanak felül az adatok', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'SERIAL';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[LASTCHANGED].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'	A rekord utolsó módosításának időpontja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'LASTCHANGED';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[CREATED].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord létrehozásának időpontja ', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'CREATED';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[MODIFIER].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekordot utoljára módosító felhasználó ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'MODIFIER';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[CREATOR].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekordot létrehozó felhasználó ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'CREATOR';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[ELOZOTANEVIREKORDID].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord előző tanévben lévő ID-ja', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'ELOZOTANEVIREKORDID';


GO
PRINT N'Creating Extended Property [dbo].[T_KEPESITESTIPUS].[ELOZOTANEVIREKORDIDA].[MS_Description]...';


GO
EXECUTE dev.uspAddOrUpdateExtendedProperty @name = N'MS_Description', @value = N'A rekord előző tanévben lévő ID-ja (altábla esetén) ', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'T_KEPESITESTIPUS', @level2type = N'COLUMN', @level2name = N'ELOZOTANEVIREKORDIDA';


GO


GO
ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH CHECK CHECK CONSTRAINT [FK_KepesitesTipus_AlIntezmenyId_REF_Intezmeny];

ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH CHECK CHECK CONSTRAINT [FK_KepesitesTipus_AlTanevId_REF_Tanev];

ALTER TABLE [dbo].[T_KEPESITESTIPUS] WITH CHECK CHECK CONSTRAINT [FK_KepesitesTipus_Id_AlintezmenyId_AltanevId_REF_DictionaryItemBase];

ALTER TABLE [dbo].[T_MUNKAUGYIADATOK] WITH CHECK CHECK CONSTRAINT [FK_MunkaugyiAdatok_KepesitesTipusId_IntezmenyId_TanevId_REF_KepesitesTipus];


GO
PRINT N'Update complete.';


GO


EXEC dev.uspCreateSchemaViews 'T_KEPESITESTIPUS, T_MUNKAUGYIADATOK, T_TANULOTANUGYIADATOK, T_TANULO'
GO

EXEC dev.sp_Global_GenerateAsyncAuditTriggerAll
GO

ALTER QUEUE auditLog.[AuditQueue]
WITH ACTIVATION (
  STATUS = ON,
  PROCEDURE_NAME = auditLog.usp_AuditProcessing,
  MAX_QUEUE_READERS = 10,
  EXECUTE AS 'Kreta_tech_user'
);
GO

