public void GenerateSchema(string SchemaName)
        {
            Logger?.Info("Database Schema check/generation started");

            var schema = db.GetSchema("Tables");

            foreach (DataRow?row in schema.Rows)
            {
                if (row == null)
                {
                    continue;
                }
                var dbName  = row[0]?.ToString();
                var schName = row[1].ToString();
                var tblName = row[2].ToString();
                if (schName == SchemaName && tblName != null)
                {
                    ExistedTables.Add(tblName);
                }
            }

            foreach (var c in tableClasses)
            {
                if (!c.IsClass)
                {
                    continue;
                }
                var orm = new ORMLite(db);
                CreateTable(c);
            }


            var sqls = PostGenerationScript.Split(";");

            foreach (var sql in sqls)
            {
                var lsql = inlineCommentsRgx.Replace(sql, "");
                if (!string.IsNullOrEmpty(lsql))
                {
                    try
                    {
                        db.Transaction((th) => th.ExecuteNonQuery(lsql));
                    }
                    #pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception ex)
                    {
                        Logger?.Error(ex, $"DBSchemaGenerator. Operation: {lsql.Trim()} ");
                    }
                    #pragma warning restore CA1031 // Do not catch general exception types
                }
            }
            Logger?.Info("Database Schema check/generation done");
        }
Esempio n. 2
0
 public void Transaction(Action <ORMTransactionHelper> ac)
 {
     con.Transaction((tr) =>
     {
         try
         {
             var th = new ORMTransactionHelper(tr);
             ac(th);
         }
         catch (Exception)
         {
             throw;
         }
     });
 }