--
-- Telefónica Digital - Product Development and Innovation
--
-- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
-- EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
--
-- Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
-- All rights reserved.
--

# Support multiple authentication backends

# --- !Ups
DROP INDEX `tu_id_UNIQUE` ON `user`;
ALTER TABLE `user` ADD `auth_realm` VARCHAR(45) NOT NULL DEFAULT 'default';
ALTER TABLE `user` CHANGE `user_id` `auth_id` VARCHAR(45) NOT NULL;
ALTER TABLE `user` ADD UNIQUE `auth_UNIQUE` (`auth_realm` ASC, `auth_id` ASC);
ALTER TABLE `user` ADD UNIQUE `handle_UNIQUE` (`handle` ASC);

# --- !Downs
DROP INDEX `auth_UNIQUE` ON `user`;
ALTER TABLE `user` DROP COLUMN `auth_realm`;
ALTER TABLE `user` CHANGE `auth_id` `user_id` VARCHAR(45) NULL;
CREATE INDEX `tu_id_UNIQUE` on `user` (`user_id` ASC);

--
-- Telefónica Digital - Product Development and Innovation
--
-- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
-- EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
--
-- Copyright (c) Telefónica Investigación y Desarrollo S.A.U.
-- All rights reserved.
--

# Support multiple authentication backends

# --- !Ups
DROP INDEX `tu_id_UNIQUE` ON `user`;
ALTER TABLE `user` ADD `auth_realm` VARCHAR(45) NOT NULL DEFAULT 'tuid';
ALTER TABLE `user` CHANGE `user_id` `auth_id` VARCHAR(45) NOT NULL;
ALTER TABLE `user` ADD UNIQUE `auth_UNIQUE` (`auth_realm` ASC, `auth_id` ASC);
ALTER TABLE `user` ADD UNIQUE `handle_UNIQUE` (`handle` ASC);

# --- !Downs
DROP INDEX `auth_UNIQUE` ON `user`;
ALTER TABLE `user` DROP COLUMN `auth_realm`;
ALTER TABLE `user` CHANGE `auth_id` `user_id` VARCHAR(45) NULL;
CREATE INDEX `tu_id_UNIQUE` on `user` (`user_id` ASC);

Improve back-compatibility of database evolutions
Improve back-compatibility of database evolutions

Change default authentication realm from 'default' to 'tuid' to
improve back-compatibility as all pre-existing accounts have that
OAuth provider.
