feat: add database models, migration & context
This commit is contained in:
parent
4cbc5f307b
commit
76368ed59e
28
netxml2kml/Data/DatabaseContext.cs
Normal file
28
netxml2kml/Data/DatabaseContext.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using netxml2kml.Models;
|
||||||
|
|
||||||
|
namespace netxml2kml.Data;
|
||||||
|
|
||||||
|
public sealed class DatabaseContext : DbContext
|
||||||
|
{
|
||||||
|
public DbSet<WirelessNetwork> WirelessNetworks { get; set; } = null!;
|
||||||
|
public DbSet<WirelessClient> WirelessClients { get; set; } = null!;
|
||||||
|
|
||||||
|
private string DbPath { get; }
|
||||||
|
|
||||||
|
public DatabaseContext()
|
||||||
|
{
|
||||||
|
var folder = Environment.SpecialFolder.LocalApplicationData;
|
||||||
|
var path = Path.Join(Environment.GetFolderPath(folder), "netxml2kml");
|
||||||
|
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
DbPath = Path.Join(path, "netxml2kml.sqlite3.db");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||||
|
=> options.UseSqlite($"Data Source={DbPath}");
|
||||||
|
}
|
119
netxml2kml/Migrations/20220810152156_InitialCreate.Designer.cs
generated
Normal file
119
netxml2kml/Migrations/20220810152156_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using netxml2kml.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace netxml2kml.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20220810152156_InitialCreate")]
|
||||||
|
partial class InitialCreate
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.8");
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessClient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Mac")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Manufacturer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("TotalPackets")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("WirelessClients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessNetwork", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Bssid")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Channel")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Encryption")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("FirstSeen")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("FrequencyMhz")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCloaked")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastUpdate")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Manufacturer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("MaxAltitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("MaxLatitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("MaxLongitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<int>("MaxSignalDbm")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Ssid")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("TotalPackets")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("WirelessClientId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("WirelessClientId");
|
||||||
|
|
||||||
|
b.ToTable("WirelessNetworks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessNetwork", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("netxml2kml.Models.WirelessClient", "WirelessClient")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("WirelessClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("WirelessClient");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
netxml2kml/Migrations/20220810152156_InitialCreate.cs
Normal file
75
netxml2kml/Migrations/20220810152156_InitialCreate.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace netxml2kml.Migrations
|
||||||
|
{
|
||||||
|
public partial class InitialCreate : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "WirelessClients",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Mac = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Manufacturer = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
TotalPackets = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_WirelessClients", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "WirelessNetworks",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
Ssid = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
IsCloaked = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||||
|
Encryption = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Bssid = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Manufacturer = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Channel = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
FrequencyMhz = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
MaxSignalDbm = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
MaxLatitude = table.Column<double>(type: "REAL", nullable: false),
|
||||||
|
MaxLongitude = table.Column<double>(type: "REAL", nullable: false),
|
||||||
|
MaxAltitude = table.Column<double>(type: "REAL", nullable: false),
|
||||||
|
FirstSeen = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
LastUpdate = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||||
|
TotalPackets = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
WirelessClientId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_WirelessNetworks", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_WirelessNetworks_WirelessClients_WirelessClientId",
|
||||||
|
column: x => x.WirelessClientId,
|
||||||
|
principalTable: "WirelessClients",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_WirelessNetworks_WirelessClientId",
|
||||||
|
table: "WirelessNetworks",
|
||||||
|
column: "WirelessClientId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "WirelessNetworks");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "WirelessClients");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
117
netxml2kml/Migrations/DatabaseContextModelSnapshot.cs
Normal file
117
netxml2kml/Migrations/DatabaseContextModelSnapshot.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using netxml2kml.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace netxml2kml.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
partial class DatabaseContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "6.0.8");
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessClient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Mac")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Manufacturer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("TotalPackets")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("WirelessClients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessNetwork", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Bssid")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("Channel")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Encryption")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("FirstSeen")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("FrequencyMhz")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCloaked")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastUpdate")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Manufacturer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("MaxAltitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("MaxLatitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("MaxLongitude")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<int>("MaxSignalDbm")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Ssid")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int>("TotalPackets")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("WirelessClientId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("WirelessClientId");
|
||||||
|
|
||||||
|
b.ToTable("WirelessNetworks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("netxml2kml.Models.WirelessNetwork", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("netxml2kml.Models.WirelessClient", "WirelessClient")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("WirelessClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("WirelessClient");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
netxml2kml/Models/WirelessClient.cs
Normal file
10
netxml2kml/Models/WirelessClient.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace netxml2kml.Models;
|
||||||
|
|
||||||
|
public class WirelessClient
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Mac { get; set; } = null!;
|
||||||
|
public string Manufacturer { get; set; } = null!;
|
||||||
|
public int TotalPackets { get; set; }
|
||||||
|
}
|
30
netxml2kml/Models/WirelessNetwork.cs
Normal file
30
netxml2kml/Models/WirelessNetwork.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
namespace netxml2kml.Models;
|
||||||
|
|
||||||
|
public class WirelessNetwork
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Ssid { get; set; } = null!;
|
||||||
|
public bool IsCloaked { get; set; }
|
||||||
|
public string Encryption { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Bssid { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Manufacturer { get; set; } = null!;
|
||||||
|
|
||||||
|
public int Channel { get; set; }
|
||||||
|
public int FrequencyMhz { get; set; }
|
||||||
|
|
||||||
|
public int MaxSignalDbm { get; set; }
|
||||||
|
|
||||||
|
public double MaxLatitude { get; set; }
|
||||||
|
public double MaxLongitude { get; set; }
|
||||||
|
public double MaxAltitude { get; set; }
|
||||||
|
|
||||||
|
public DateTime FirstSeen { get; set; }
|
||||||
|
public DateTime LastUpdate { get; set; }
|
||||||
|
|
||||||
|
public int TotalPackets { get; set; }
|
||||||
|
|
||||||
|
public WirelessClient WirelessClient { get; set; } = null!;
|
||||||
|
}
|
@ -8,7 +8,16 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.8" />
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user