Fixed: Database migration failure when database was manually repaired in a certain way
fixes #4390
This commit is contained in:
parent
d6c0635a26
commit
34faa417c1
|
@ -25,6 +25,7 @@ namespace NzbDrone.Core.Test.Datastore.SqliteSchemaDumperTests
|
|||
[TestCase(@"CREATE TABLE ""Test """"Table"" (""My""""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)", "Test \"Table", "My\"Id")]
|
||||
[TestCase(@"CREATE TABLE [Test Table] ([My Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT)", "Test Table", "My Id")]
|
||||
[TestCase(@" CREATE TABLE `Test ``Table` ( `My`` Id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ) ", "Test `Table", "My` Id")]
|
||||
[TestCase(@"CREATE TABLE TestTable (MyId INTEGER NOT NULL, PRIMARY KEY(""MyId"" AUTOINCREMENT))", "TestTable", "MyId")]
|
||||
public void should_parse_table_language_flavors(string sql, string tableName, string columnName)
|
||||
{
|
||||
var result = Subject.ReadTableSchema(sql);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using FluentMigrator.Model;
|
||||
using FluentMigrator.Runner;
|
||||
using FluentMigrator.Runner.Processors.SQLite;
|
||||
|
@ -67,6 +68,23 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||
|
||||
if (columnReader.Read() == SqliteSyntaxReader.TokenType.StringToken)
|
||||
{
|
||||
if (columnReader.ValueToUpper == "PRIMARY")
|
||||
{
|
||||
columnReader.SkipTillToken(SqliteSyntaxReader.TokenType.ListStart);
|
||||
if (columnReader.Read() == SqliteSyntaxReader.TokenType.Identifier)
|
||||
{
|
||||
var pk = table.Columns.First(v => v.Name == columnReader.Value);
|
||||
pk.IsPrimaryKey = true;
|
||||
pk.IsNullable = true;
|
||||
pk.IsUnique = true;
|
||||
if (columnReader.Buffer.ToUpperInvariant().Contains("AUTOINCREMENT"))
|
||||
{
|
||||
pk.IsIdentity = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (columnReader.ValueToUpper == "CONSTRAINT" ||
|
||||
columnReader.ValueToUpper == "PRIMARY" || columnReader.ValueToUpper == "UNIQUE" ||
|
||||
columnReader.ValueToUpper == "CHECK" || columnReader.ValueToUpper == "FOREIGN")
|
||||
|
|
|
@ -148,9 +148,9 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||
{
|
||||
var start = Index;
|
||||
var end = start + 1;
|
||||
while (end < Buffer.Length && (char.IsLetter(Buffer[end]) || char.IsNumber(Buffer[end]) || Buffer[end] == '_' || Buffer[end] == '(')) end++;
|
||||
while (end < Buffer.Length && (char.IsLetter(Buffer[end]) || char.IsNumber(Buffer[end]) || Buffer[end] == '_')) end++;
|
||||
|
||||
if (end >= Buffer.Length || Buffer[end] == ',' || Buffer[end] == ')' || char.IsWhiteSpace(Buffer[end]))
|
||||
if (end >= Buffer.Length || Buffer[end] == ',' || Buffer[end] == '(' || Buffer[end] == ')' || char.IsWhiteSpace(Buffer[end]))
|
||||
{
|
||||
Index = end;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue