static List <SqlTable> ParseMetadata(DatabaseContext context) { var parser = new SqlSchemaParser(); var metadata = new List <SqlTable>(); foreach (var fromQuery in context.FromQueries) { var stmt = parser.ParseCreateTable(fromQuery); var columns = stmt.Columns; var foreignKeys = new List <SqlForeignKey>(); foreach (var foreignKey in fromQuery.ForeignKeys) { var foreignKeyStmt = parser.ParseAddForeignKey(fromQuery, foreignKey); foreignKeys.Add(foreignKeyStmt.ForeignKey); } var indices = new List <SqlIndex>(); foreach (var index in fromQuery.Indices) { var indexStmt = parser.ParseAddIndex(fromQuery, index); indices.Add(indexStmt.Index); } metadata.Add(new SqlTable() { TableName = fromQuery.TableName, Columns = columns, ForeignKeys = foreignKeys, Indices = indices, }); } return(metadata); }
public void EnsureMigrationTable(SqlQueryRunner runner) { var parser = new SqlSchemaParser(); var createTable = parser.ParseCreateTable(Context.Migrations); try { runner.ExecuteNonQuery(new List <SqlStatement>() { createTable }, new List <KeyValuePair <string, object> >()); } catch (Exception) { // Ignore exception when the table already exists. } }