## mysql
# A_ImageBlockCacheMap_1.0
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap
  DROP INDEX DB_COLUMN_PREFIXuserId,
  ADD INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap
  ADD COLUMN DB_COLUMN_PREFIXrandom int(11),
  ADD INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap
  DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215,
  DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627,
  ADD INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId int(11) NOT NULL,
 DB_COLUMN_PREFIXitemType int(11) NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp int(11) NOT NULL,
 DB_COLUMN_PREFIXitemId int(11) NOT NULL,
 DB_COLUMN_PREFIXrandom int(11),
 INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom)
) DB_TABLE_TYPE
/*!40100 DEFAULT CHARACTER SET utf8 */;

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId int(11) NOT NULL,
 PRIMARY KEY(DB_COLUMN_PREFIXitemId)
) DB_TABLE_TYPE
/*!40100 DEFAULT CHARACTER SET utf8 */;

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

## postgres
# A_ImageBlockCacheMap_1.0
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap ADD COLUMN DB_COLUMN_PREFIXrandom INTEGER;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215;

DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemType INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL,
 DB_COLUMN_PREFIXrandom INTEGER
);

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL
);

ALTER TABLE DB_TABLE_PREFIXImageBlockDisabledMap ADD PRIMARY KEY (DB_COLUMN_PREFIXitemId);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

## oracle
# A_ImageBlockCacheMap_1.0
  DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap
  ADD (DB_COLUMN_PREFIXrandom INTEGER);

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
  DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215;

  DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemType INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL,
 DB_COLUMN_PREFIXrandom INTEGER
);

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758
   ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL
);

ALTER TABLE DB_TABLE_PREFIXImageBlockDisabledMap
 ADD PRIMARY KEY (DB_COLUMN_PREFIXitemId)
;

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

## db2
# A_ImageBlockCacheMap_1.0
DROP INDEX DB_TABLE_PREFIXImage05_1627;

CREATE INDEX DB_TABLE_PREFIXImage05_1627 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap ADD COLUMN DB_COLUMN_PREFIXrandom INTEGER;

CREATE INDEX DB_TABLE_PREFIXImage05_80215 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
DROP INDEX DB_TABLE_PREFIXImage05_80215;

DROP INDEX DB_TABLE_PREFIXImage05_1627;

CREATE INDEX DB_TABLE_PREFIXImage05_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemType INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL,
 DB_COLUMN_PREFIXrandom INTEGER
);

CREATE INDEX DB_TABLE_PREFIXImage05_48758
   ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL
);

ALTER TABLE DB_TABLE_PREFIXImageBlockDisabledMap ADD PRIMARY KEY (DB_COLUMN_PREFIXitemId);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

## mssql
# A_ImageBlockCacheMap_1.0
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap.DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap ADD DB_COLUMN_PREFIXrandom INT NULL;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap.DB_TABLE_PREFIXImageBlockCacheMap_80215;

DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap.DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId INT NOT NULL,
 DB_COLUMN_PREFIXitemType INT NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp INT NOT NULL,
 DB_COLUMN_PREFIXitemId INT NOT NULL,
 DB_COLUMN_PREFIXrandom INT NULL
);

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId INT NOT NULL
);

ALTER TABLE DB_TABLE_PREFIXImageBlockDisabledMap ADD PRIMARY KEY (DB_COLUMN_PREFIXitemId);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

## sqlite
# A_ImageBlockCacheMap_1.0
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=1
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=0;

# A_ImageBlockCacheMap_1.1
ALTER TABLE DB_TABLE_PREFIXImageBlockCacheMap ADD DB_COLUMN_PREFIXrandom INTEGER;
VACUUM DB_TABLE_PREFIXImageBlockCacheMap;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXrandom, DB_COLUMN_PREFIXitemId);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=2
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=1;

# A_ImageBlockCacheMap_1.2
DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_80215;

DROP INDEX DB_TABLE_PREFIXImageBlockCacheMap_1627;

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

UPDATE DB_TABLE_PREFIXSchema
  SET DB_COLUMN_PREFIXmajor=1, DB_COLUMN_PREFIXminor=3
  WHERE DB_COLUMN_PREFIXname='ImageBlockCacheMap' AND DB_COLUMN_PREFIXmajor=1 AND DB_COLUMN_PREFIXminor=2;

# ImageBlockCacheMap
CREATE TABLE DB_TABLE_PREFIXImageBlockCacheMap(
 DB_COLUMN_PREFIXuserId INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemType INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemTimestamp INTEGER NOT NULL,
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL,
 DB_COLUMN_PREFIXrandom INTEGER
);

CREATE INDEX DB_TABLE_PREFIXImageBlockCacheMap_48758 ON DB_TABLE_PREFIXImageBlockCacheMap(DB_COLUMN_PREFIXuserId, DB_COLUMN_PREFIXitemType, DB_COLUMN_PREFIXrandom);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockCacheMap', 1, 3);

# ImageBlockDisabledMap
CREATE TABLE DB_TABLE_PREFIXImageBlockDisabledMap(
 DB_COLUMN_PREFIXitemId INTEGER NOT NULL
);

CREATE UNIQUE INDEX DB_TABLE_PREFIXImageBlockDisabledMap_pkey ON DB_TABLE_PREFIXImageBlockDisabledMap(DB_COLUMN_PREFIXitemId);

INSERT INTO DB_TABLE_PREFIXSchema (
 DB_COLUMN_PREFIXname,
 DB_COLUMN_PREFIXmajor,
 DB_COLUMN_PREFIXminor
) VALUES('ImageBlockDisabledMap', 1, 0);

