The team of developers I work with are using SQL Data Projects for a large piece of work we have to do against an existing database. We are a few weeks in and there have been a few gotchas, but the experience has been generally good.
However, when we get to deploy to production, the dba team have refused to accept DACPACs as a deployment method. Instead, they are want to see a traditional script per DML or DDL statement.
The current thinking is to create a difference script between the finished SQL project and the production environment, and then parse that into individual scripts. Not nice I know.
To parse the difference script there seems to be two options:
- Parse the script based on the batch separator command, GO. A rather basic solutions but shows promise.
- Or, use the Microsoft.SqlServer.TransactSql.ScriptDom. This looks more future proof but seems far more complex.
I'm trialling the ScriptDom at the moment but am having trouble understanding it. My current, but not only issues, is as follows.
I'm trying to parse the following SQL using the ScriptDOM in C#:
CREATE TABLE dbo.MyTable
(
MyColumn VARCHAR(255)
)
But cannot see how to access the VARCHAR size, in this case, 255.
The code I'm using is as follows:
TSqlFragment sqlFragment = parser.Parse(textReader, out errors);
SQLVisitor myVisitor = new SQLVisitor();
sqlFragment.Accept(myVisitor);
public override void ExplicitVisit(CreateTableStatement node)
{
// node.SchemaObjectName.Identifiers to access the table name
// node.Definition.ColumnDefinitions to access the column attributes
}
From each column definition I expected to find a length property or similar. However, I also have a sneaking suspicion that you can use the Visitor Pattern, which I struggle with, to reparse each column definition. Any ideas?