示例#1
0
        public void Migrate(DatabaseConnection connection)
        {
            connection.RunInTransaction(db => {
                var selectTable = "select name from sqlite_master where type='table' and name not like 'sqlite_%';";
                List <string> tables;
                using (var entitiesStatetment = db.PrepareStatement(selectTable))
                {
                    tables = entitiesStatetment.ExecuteQuery().Select(row => row.GetString(0)).ToList();
                }

                foreach (var table in tables)
                {
                    db.Execute($"drop table '{table}';");
                }

                var selectIndex = "select name from sqlite_master where type='index' and name not like 'sqlite_%';";
                List <string> indexes;
                using (var indexesStatetment = db.PrepareStatement(selectIndex))
                {
                    indexes = indexesStatetment.ExecuteQuery().Select(row => row.GetString(0)).ToList();
                }

                foreach (var index in indexes)
                {
                    db.Execute($"drop index '{index}';");
                }
            }, TransactionMode.Deferred);
        }
示例#2
0
        public void Migrate(DatabaseConnection connection)
        {
            connection.RunInTransaction(db =>
            {
                if (!db.TableExists("user_info"))
                {
                    return;
                }

                string createQuery =
#if EMBY
                    "create table if not exists user_info_tmp(Id TEXT NOT NULL, Guid GUID NOT NULL, UserId TEXT NOT NULL, LastModified INTEGER NOT NULL, Type TEXT NOT NULL, PRIMARY KEY (Id, UserId))";
#else
                    "create table if not exists user_info_tmp(Guid GUID NOT NULL, UserId TEXT NOT NULL, LastModified INTEGER NOT NULL, Type TEXT NOT NULL, PRIMARY KEY (Guid, UserId))";
#endif
                db.Execute(createQuery);
                db.Execute("insert into user_info_tmp select * from user_info");
                db.Execute("drop table user_info");
                db.Execute("alter table user_info_tmp rename to user_info");

                string createIndex =
#if EMBY
                    "create index if not exists idx_user_info on user_info(Id, UserId)";
#else
                    "create index if not exists idx_user_info on user_info(Guid, UserId)";
#endif
                db.Execute(createIndex);
            }, TransactionMode.Deferred);
        }