Commit d173cedf authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Sprint/2020-07' into 'master'

Sprint/2020-07

See merge request coscine/cs/migrations!11
parents 6a0d3024 80e1f8a7
......@@ -13,17 +13,17 @@ namespace Coscine.Database.Migration.Migrations
{
public override void Down()
{
HandleInstitute((obj) => Delete.FromTable("Institutes").Row(obj));
HandleDiscipline((obj) => Delete.FromTable("Disciplines").Row(obj));
MigrationsHelpers.HandleInstitute((obj) => Delete.FromTable("Institutes").Row(obj));
MigrationsHelpers.HandleDiscipline((obj) => Delete.FromTable("Disciplines").Row(obj));
}
public override void Up()
{
HandleInstitute((obj) => Insert.IntoTable("Institutes").Row(obj));
HandleDiscipline((obj) => Insert.IntoTable("Disciplines").Row(obj));
MigrationsHelpers.HandleInstitute((obj) => Insert.IntoTable("Institutes").Row(obj));
MigrationsHelpers.HandleDiscipline((obj) => Insert.IntoTable("Disciplines").Row(obj));
}
private void HandleInstitute(Action<object> action)
internal void HandleInstitute(Action<object> action)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Coscine.Database.Migration.Assets.Institutes.csv";
......@@ -44,35 +44,5 @@ namespace Coscine.Database.Migration.Migrations
}
}
}
private void HandleDiscipline(Action<object> action)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Coscine.Database.Migration.Assets.dfg_structure.rdf";
using (var stream = assembly.GetManifestResourceStream(resourceName))
using (XmlReader reader = XmlReader.Create(stream))
{
reader.MoveToContent();
XNamespace skosNameSpace = "http://www.w3.org/2004/02/skos/core#";
XNamespace rdfNameSpace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "skos:Concept")
{
XElement el = (XElement) XNode.ReadFrom(reader);
var notation = el.Element(skosNameSpace + "notation");
if (int.TryParse(notation.Value, out int val) && notation.Value.Length == 3)
{
var url = el.Attribute(rdfNameSpace + "about").Value;
action.Invoke(new { DisplayName = el.Element(skosNameSpace + "prefLabel").Value, Url = url });
}
}
}
}
}
}
}
}
using FluentMigrator;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
#region DupFinder Exclusion
namespace Coscine.Database.Migration.Migrations
......
using FluentMigrator;
using System;
#region DupFinder Exclusion
namespace Coscine.Database.Migration.Migrations
{
//yyyymmddhhmm
[Migration(202003231800)]
public class Migration202003231800Organizations : FluentMigrator.Migration
{
public override void Down()
{
Create.Table("Institutes")
.WithColumn("Id").AsGuid().PrimaryKey().WithDefault(SystemMethods.NewGuid)
.WithColumn("DisplayName").AsString(200).NotNullable()
.WithColumn("IKZ").AsString(20).NotNullable();
MigrationsHelpers.HandleInstitute((obj) => Insert.IntoTable("Institutes").Row(obj));
Delete.Column("OrganizationUrl").FromTable("ProjectInstitute");
// Nullable because no better solution was found to add a foreign key relation without clearing the tables involved
Alter.Table("ProjectInstitute").AddColumn("InstituteId").AsGuid().Nullable();
Create.ForeignKey()
.FromTable("ProjectInstitute").ForeignColumn("InstituteId")
.ToTable("Institutes").PrimaryColumn("Id");
}
public override void Up()
{
Delete.ForeignKey("FK_ProjectInstitute_InstituteId_Institutes_Id").OnTable("ProjectInstitute");
Delete.Column("InstituteId").FromTable("ProjectInstitute");
Delete.Table("Institutes");
Alter.Table("ProjectInstitute")
.AddColumn("OrganizationUrl")
.AsString(255)
.NotNullable()
.WithDefaultValue("https://www.rwth-aachen.de/22000"); // Migration value for IT Center
}
}
}
#endregion
using FluentMigrator;
namespace Coscine.Database.Migration.Migrations
{
//yyyymmddhhmm
[Migration(202004151354)]
public class Migration202004151354S3ResourceUrl : FluentMigrator.Migration
{
public override void Down()
{
Delete.Column("ResourceUrl").FromTable("S3ResourceType");
}
public override void Up()
{
Alter.Table("S3ResourceType").AddColumn("ResourceUrl").AsString(200).Nullable();
Update.Table("S3ResourceType").Set(new { ResourceUrl = "https://s3.rwth-aachen.de" }).AllRows();
Alter.Table("S3ResourceType").AlterColumn("ResourceUrl").AsString(200).NotNullable();
}
}
}
using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
namespace Coscine.Database.Migration
{
public class MigrationsHelpers
{
public static void HandleInstitute(Action<object> action)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Coscine.Database.Migration.Assets.Institutes.csv";
using (var stream = assembly.GetManifestResourceStream(resourceName))
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line.Contains(","))
{
var values = line.Split(',');
if (values[0].Trim() != "" && values[1].Trim() != "")
{
action.Invoke(new { IKZ = values[0].Trim(), DisplayName = values[1].Trim() });
}
}
}
}
}
public static void HandleDiscipline(Action<object> action)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "Coscine.Database.Migration.Assets.dfg_structure.rdf";
using (var stream = assembly.GetManifestResourceStream(resourceName))
using (XmlReader reader = XmlReader.Create(stream))
{
reader.MoveToContent();
XNamespace skosNameSpace = "http://www.w3.org/2004/02/skos/core#";
XNamespace rdfNameSpace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "skos:Concept")
{
XElement el = (XElement)XNode.ReadFrom(reader);
var notation = el.Element(skosNameSpace + "notation");
if (int.TryParse(notation.Value, out int val) && notation.Value.Length == 3)
{
var url = el.Attribute(rdfNameSpace + "about").Value;
action.Invoke(new { DisplayName = el.Element(skosNameSpace + "prefLabel").Value, Url = url });
}
}
}
}
}
}
}
}
......@@ -143,6 +143,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MigrationsHelpers.cs" />
<Compile Include="Migrations\Migration201907011352ProjectApi.cs" />
<Compile Include="Migrations\Migration201907081510EnhanceProjectApi.cs" />
<Compile Include="Migrations\Migration201910021300ResourceDescription.cs" />
......@@ -165,7 +166,9 @@
<Compile Include="Migrations\Migration202001270800ResourceFlags.cs" />
<Compile Include="Migrations\Migration202002041409ProjectDeletedColumn.cs" />
<Compile Include="Migrations\Migration202002101300MoreLicenses.cs" />
<Compile Include="Migrations\Migration202003231800Organizations.cs" />
<Compile Include="Migrations\Migration202003121255ActivatedFeatures.cs" />
<Compile Include="Migrations\Migration202004151354S3ResourceUrl.cs" />
<Compile Include="Migrations\Migration202003192117ORCiDEmailAddress.cs" />
<Compile Include="Migrator.cs" />
<Compile Include="Program.cs" />
......
......@@ -11,6 +11,6 @@ using System.Reflection;
[assembly: AssemblyProduct("Migrator")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0-topic-670-apiref0003")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment