Ejemplo n.º 1
0
        /// <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}.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 public virtual void OnBeforeInsert(VolyContext context)
 {
 }
Ejemplo n.º 4
0
 public override void OnBeforeInsert(VolyContext context)
 {
     CreateDate = DateTime.UtcNow;
     base.OnBeforeInsert(context);
 }
Ejemplo n.º 5
0
 public override void OnBeforeInsert(VolyContext context)
 {
     Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
     base.OnBeforeInsert(context);
 }
Ejemplo n.º 6
0
 public virtual void OnBeforeDelete(VolyContext context)
 {
 }
Ejemplo n.º 7
0
 public virtual void OnBeforeUpdate(VolyContext context)
 {
 }
Ejemplo n.º 8
0
 /// <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);
 }