/// <summary> /// I don't like the built in EF upgrade system. /// </summary> private static void Upgrade(VolyContext context, ILogger log) { var dbVersion = context.Configuration.Where(x => x.Key == "version").FirstOrDefault(); if (dbVersion == null || string.IsNullOrWhiteSpace(dbVersion.Value) || !int.TryParse(dbVersion.Value, out int version)) { context.Configuration.Add(new Configuration() { Key = "version", Value = UpgradesOffsetCount.ToString() }); context.SaveChanges(); if (log != null) { log.LogInformation($"Database created at version {UpgradesOffsetCount}."); } } else { while (version < UpgradesOffsetCount) { Upgrades[UpgradesOffsetIndex(version)].Invoke(context); version++; } if (dbVersion.Value != UpgradesOffsetCount.ToString()) { dbVersion.Value = UpgradesOffsetCount.ToString(); context.SaveChanges(); if (log != null) { log.LogInformation($"Database upgraded to version {dbVersion.Value}."); } } } }
public override void OnBeforeDelete(VolyContext context) { context.TransactionLog.Add(new TransactionLog() { TableName = TransactionTableType.MediaItem, Type = TransactionType.Delete, Key = MediaId, Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }); base.OnBeforeDelete(context); }
public virtual void OnBeforeInsert(VolyContext context) { }
public override void OnBeforeInsert(VolyContext context) { CreateDate = DateTime.UtcNow; base.OnBeforeInsert(context); }
public override void OnBeforeInsert(VolyContext context) { Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); base.OnBeforeInsert(context); }
public virtual void OnBeforeDelete(VolyContext context) { }
public virtual void OnBeforeUpdate(VolyContext context) { }
/// <summary> /// Initializes the database if it doesn't exist, and upgrades it to the latest version if it does. /// </summary> public static void Initialize(VolyContext context, ILogger log) { context.Database.EnsureCreated(); Upgrade(context, log); }