public void PrepareTestDatabase() { Console.WriteLine("Setting up database."); //Connect & ensure creation DBContext = new DataGovernanceDBContext( new DbContextOptionsBuilder <DataGovernanceDBContext>() .UseNpgsql("Host=localhost;Database=DataGovernanceToolTestDB;Username=datagovernancetool;Password=datagovernancetool") .Options); }
public IntopaloController(DataGovernanceDBContext context) { _context = context; if (_context.Collections.Count() == 0) { // Create a new IntopaloItem if collection is empty, // which means you can't delete all IntopaloItems. _context.Collections.Add(new Collection { CollectionName = "IntopaloCollection1" }); _context.SaveChanges(); } if (_context.Schemas.Count() == 0) { _context.Schemas.Add( new Schema { SchemaName = "private", Tables = new List <Table> { new Table { TableName = "User", Fields = new List <Field> { new Field { FieldName = "UserId", FieldType = "int" }, new Field { FieldName = "UserName", FieldType = "nvarchar(max)" } } }, new Table { TableName = "Car", Fields = new List <Field> { new Field { FieldName = "CarId", FieldType = "int" }, new Field { FieldName = "OwnerId", FieldType = "int" }, new Field { FieldName = "CarBrand", FieldType = "nvarchar(max)" } } } } } ); _context.SaveChanges(); _context.KeyRelationships.Add(new KeyRelationship { BaseFromId = _context.Fields.Single(f => f.FieldName == "UserId").BaseID, BaseToId = _context.Fields.Single(f => f.FieldName == "OwnerId").BaseID, Type = "exact" }); _context.SaveChanges(); } }
public DataGTController(DataGovernanceDBContext context) { _context = context; if (_context.Datastores.Count() == 0) { _context.Datastores.Add(new Datastore { Name = "Store1", PostgresDatabases = new List <PostgresDatabase> { new PostgresDatabase { Name = "UserDB", Type = "PostgreSQL", Schemas = new List <Schema> { new Schema { Name = "private", Tables = new List <Table> { new Table { Name = "User", Fields = new List <Field> { new Field { Name = "UserId", Type = "int" }, new Field { Name = "UserName", Type = "nvarchar(max)" } } }, new Table { Name = "Car", Fields = new List <Field> { new Field { Name = "CarId", Type = "int" }, new Field { Name = "OwnerId", Type = "int" }, new Field { Name = "CarBrand", Type = "nvarchar(max)" }, new Field { Name = "document", Type = "JSON", Fields = new List <Field> { new Field { Name = "a", Type = "JSON", Fields = new List <Field> { new Field { Name = "b", Type = "JSON_int" } } } } } } } } } } } } }); _context.SaveChanges(); _context.KeyRelationships.Add(new KeyRelationship { FromId = _context.Fields.Single(f => f.Name == "UserId").Id, ToId = _context.Fields.Single(f => f.Name == "OwnerId").Id, Type = "exact" }); _context.Annotations.Add(new Annotation { Description = "sensitive" }); _context.Annotations.Add(new Annotation { Description = "encrypted" }); _context.Annotations.Add(new Annotation { Description = "private" }); _context.AnnotationBases.Add(new AnnotationBase { BaseId = _context.Fields.Single(f => f.Name == "Name").Id, AnnotationId = _context.Annotations.Single(a => a.Description == "sensitive").Id }); _context.SaveChanges(); } }