Example #1
0
        public List <CommandResult> SYNC_SCAFFOLD(IConnectToDB _Connect, string Name, string ScaffoldType, List <ColumnStructure> ColumnsList, bool useIdentityUUID = false, string RootColumn = "", bool sync = false)
        {
            List <CommandResult> HoldResult = new List <CommandResult>();
            ER_DDL      er_ddl = new ER_DDL();
            ER_Generate gen    = new ER_Generate();

            HoldResult.Add(new CommandResult
            {
                _Response   = "--Start Scaffold " + Name + "",
                _Successful = true
            });
            List <string> ColumnsList2 = new List <string>();

            ColumnsList2.Add(Name + "_ID");

            HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, Name, ScaffoldType, useIdentityUUID, RootColumn));

            bool tableAlreadyExists = (HoldResult.Exists(x => x._CommandName == "Create Table " + Name && !x._Successful));

            if (tableAlreadyExists && sync == false)
            {
                HoldResult.Add(new CommandResult
                {
                    _Response   = Name + " was already created successfully during installation",
                    _Successful = true
                });
            }
            else
            {
                HoldResult.AddRange(er_ddl.ADD_COLUMNS(_Connect, Name, ColumnsList));
                if (tableAlreadyExists == false)
                {
                    HoldResult.AddRange(er_ddl.ADD_KEY_UNIQUE(_Connect, Name + "_ID", Name, ColumnsList2));
                }
                if (useIdentityUUID || true)
                {
                    List <string> ColumnsListUUID = new List <string>();

                    if (tableAlreadyExists == false)
                    {
                        ColumnsListUUID.Add(Name + "_UUID");
                        HoldResult.AddRange(er_ddl.ADD_KEY_UNIQUE(_Connect, Name + "_UUID", Name, ColumnsListUUID));
                    }
                }

                if (tableAlreadyExists && sync)
                {
                    HoldResult.AddRange(er_ddl.DROP_PROCEDURE(_Connect, "SP_I_" + Name + ""));
                    HoldResult.AddRange(er_ddl.DROP_PROCEDURE(_Connect, "SP_U_" + Name + ""));
                    HoldResult.AddRange(er_ddl.DROP_PROCEDURE(_Connect, "SP_D_" + Name + ""));
                    HoldResult.AddRange(er_ddl.DROP_PROCEDURE(_Connect, "SP_U_MOD_" + Name + ""));
                    HoldResult.AddRange(er_ddl.DROP_PROCEDURE(_Connect, "SP_S_" + Name + "_SEARCH"));
                }
                HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, Name, ""));
                HoldResult.AddRange(ER_Generate.CreateProcedureSearchProcedure(_Connect, "Eminent IT", _Connect.Schema,
                                                                               "",
                                                                               "",
                                                                               new List <CommandResult>(),
                                                                               selectStruct: new SearchProcedureStruct
                {
                    ProcedurePrefix  = "SP_S",
                    GetLatestVersion = true,
                    ProcedureName    = Name + "_SEARCH",
                    SourceName       = Name
                }));

                HoldResult.AddRange(gen.Generate_Update_Procedure_For_Source(_Connect, Name));
                HoldResult.AddRange(gen.ADD_PROCEDURE_UPDATE(_Connect, Name, ""));
                HoldResult.AddRange(gen.ADD_PROCEDURE_DELETE(_Connect, Name, ""));
            }

            HoldResult.Add(new CommandResult
            {
                _Response   = "--EndScaffold " + Name + "",
                _Successful = true
            });

            return(HoldResult);
        }
Example #2
0
        public List <CommandResult> ADD_SCAFFOLD_ACCESS(IConnectToDB _Connect, string TableName)
        {
            string[] excludedTableNames = { "IDENTITIES", "GROUPS", "ROLES", "PRIVILEGES" };

            Tools.Box   er_tools = new Tools.Box();
            ER_Generate gen      = new ER_Generate();

            List <CommandResult> HoldResult = new List <CommandResult>();

            string newTableName    = er_tools.MaxNameLength(TableName, (128 - 16));
            string Perm_Table      = newTableName + "_SEC_PERM";
            string Role_Table      = newTableName + "_SEC_ROLE";
            string Privs_Table     = newTableName + "_SEC_PRIV";
            string GroupRole_Table = newTableName + "_SEC_GRRO";

            HoldResult.Add(new CommandResult
            {
                _Successful = true,
                _Response   = "---Start Security Scaffold " + TableName + "",
                _EndTime    = DateTime.Now
            });
            List <ColumnStructure> ColumnsList = new List <ColumnStructure>();

            //Run as long as Tables isn't listed
            if (Array.IndexOf(excludedTableNames, TableName.ToUpper()) < 0)
            {
                #region Create Tables For Permission Structures
                HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, GroupRole_Table, "Group Role"));
                //HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, Perm_Table, "Permission"));
                // HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, Privs_Table, "Privilege"));
                HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, Role_Table, "Role"));
                #endregion

                if (false)
                {
                    #region Permissions Table
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                    });
                    ColumnsList.Add(new ColumnStructure {
                        _Name = TableName + "_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "ROLES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });

                    HoldResult.AddRange(ER_DDL._ADD_COLUMNS(_Connect, Perm_Table, ColumnsList));

                    HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, Perm_Table, ""));

                    #region PERMS TABLE Foreign Keys
                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "ROLES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Perm_Table + "_1", Perm_Table, "Roles", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "IDENTITIES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Perm_Table + "_2", Perm_Table, "Identities", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Perm_Table + "_3", Perm_Table, "Objects", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = TableName + "_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Perm_Table + "_4", Perm_Table, TableName, ColumnsList, ColumnsList));
                    #endregion

                    #endregion
                }

                #region Roles Table
                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                });
                ColumnsList.Add(new ColumnStructure {
                    _Name = TableName + "_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                if (TableName.ToLower() != "applications")
                {
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "APPLICATIONS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                    });
                }
                ColumnsList.Add(new ColumnStructure {
                    _Name = "ROLES_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });

                HoldResult.AddRange(ER_DDL._ADD_COLUMNS(_Connect, Role_Table, ColumnsList));
                HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, Role_Table, ""));
                HoldResult.AddRange(gen.Generate_Update_Procedure_For_Source(_Connect, Role_Table));
                HoldResult.AddRange(gen.ADD_PROCEDURE_UPDATE(_Connect, Role_Table, ""));
                HoldResult.AddRange(gen.ADD_PROCEDURE_DELETE(_Connect, Role_Table, ""));
                HoldResult.AddRange(ER_Generate.CreateProcedureSearchProcedure(_Connect, "Eminent IT", _Connect.Schema,
                                                                               "",
                                                                               "",
                                                                               new List <CommandResult>(),
                                                                               selectStruct: new SearchProcedureStruct
                {
                    ProcedurePrefix  = "SP_S",
                    GetLatestVersion = true,
                    ProcedureName    = Role_Table + "_SEARCH",
                    SourceName       = Role_Table
                }));

                #region Foreign Keys

                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = "ROLES_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Role_Table + "_SEC_1", Role_Table, "Roles", ColumnsList, ColumnsList));

                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                });
                HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Role_Table + "_SEC_2", Role_Table, "Objects", ColumnsList, ColumnsList));

                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = TableName + "_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Role_Table + "_SEC_3", Role_Table, TableName, ColumnsList, ColumnsList));

                //if (TableName.ToLower() != "applications")
                //{
                //    ColumnsList.Clear();
                //    ColumnsList.Add(new ColumnStructure { _Name = "APPLICATIONS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = "" });
                //    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Role_Table + "_SEC_4", Role_Table, "APPLICATIONS", ColumnsList, ColumnsList));
                //}
                #endregion

                #endregion

                if (false)
                {
                    #region Privileges Table
                    ColumnsList.Clear();

                    ColumnsList.Add(new ColumnStructure {
                        _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                    });
                    ColumnsList.Add(new ColumnStructure {
                        _Name = TableName + "_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "PRIVILEGES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_COLUMNS(_Connect, Privs_Table, ColumnsList));

                    HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, Privs_Table, ""));

                    #region Priv Table Foreign Keys
                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "PRIVILEGES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Privs_Table + "_1", Privs_Table, "Privileges", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "IDENTITIES_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Privs_Table + "_2", Privs_Table, "Identities", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Privs_Table + "_3", Privs_Table, "Objects", ColumnsList, ColumnsList));

                    ColumnsList.Clear();
                    ColumnsList.Add(new ColumnStructure {
                        _Name = TableName + "_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = ""
                    });
                    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, Privs_Table + "_4", Privs_Table, TableName, ColumnsList, ColumnsList));
                    #endregion

                    #endregion
                }

                #region Group Roles Table
                ColumnsList.Clear();

                ColumnsList.Add(new ColumnStructure {
                    _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
                });
                ColumnsList.Add(new ColumnStructure {
                    _Name = TableName + "_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                if (TableName.ToLower() != "applications")
                {
                    ColumnsList.Add(new ColumnStructure {
                        _Name = "APPLICATIONS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                    });
                }
                ColumnsList.Add(new ColumnStructure {
                    _Name = "GROUPS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                ColumnsList.Add(new ColumnStructure {
                    _Name = "ROLES_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });

                HoldResult.AddRange(ER_DDL._ADD_COLUMNS(_Connect, GroupRole_Table, ColumnsList));
                HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, GroupRole_Table, ""));
                HoldResult.AddRange(gen.Generate_Update_Procedure_For_Source(_Connect, GroupRole_Table));
                HoldResult.AddRange(gen.ADD_PROCEDURE_UPDATE(_Connect, GroupRole_Table, ""));
                HoldResult.AddRange(gen.ADD_PROCEDURE_DELETE(_Connect, GroupRole_Table, ""));
                HoldResult.AddRange(ER_Generate.CreateProcedureSearchProcedure(_Connect, "Eminent IT", _Connect.Schema,
                                                                               "",
                                                                               "",
                                                                               new List <CommandResult>(),
                                                                               selectStruct: new SearchProcedureStruct
                {
                    ProcedurePrefix  = "SP_S",
                    GetLatestVersion = true,
                    ProcedureName    = GroupRole_Table + "_SEARCH",
                    SourceName       = GroupRole_Table
                }));

                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = "ROLES_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, GroupRole_Table + "_1", GroupRole_Table, "Roles", ColumnsList, ColumnsList));

                ColumnsList.Clear();
                ColumnsList.Add(new ColumnStructure {
                    _Name = "GROUPS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
                });
                HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, GroupRole_Table + "_2", GroupRole_Table, "Groups", ColumnsList, ColumnsList));

                //if (TableName.ToLower() != "applications")
                //{
                //    ColumnsList.Clear();
                //    ColumnsList.Add(new ColumnStructure { _Name = "APPLICATIONS_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = "" });
                //    HoldResult.AddRange(ER_DDL._ADD_KEY_FOREIGN(_Connect, GroupRole_Table + "_SEC_3", Role_Table, "APPLICATIONS", ColumnsList, ColumnsList));
                //}

                #endregion
            }

            HoldResult.Add(new CommandResult
            {
                _Successful = true,
                _Response   = "---End Security Scaffold " + TableName + "",
                _EndTime    = DateTime.Now
            });

            return(HoldResult);
        }