﻿select * from auth_user;


insert into auth_user
(username, first_name, last_name, email, password, is_active, is_superuser, is_staff, last_login, date_joined)

select 
lower(clave) || 'admin' as username
, case when length(nombre)>=30 then substring(nombre, 0, 27) || '...' else substring(nombre, 0, 30) end as first_name
,'Tabasco' as last_name
,lower(clave) || 'admin@tabasco.gob.mx' as email
,( select password from auth_user where id = 6 ) as password
, true as is_active
, false as is_superuser
, false as is_staff
, ( select last_login from auth_user where id = 6 ) as last_login
, ( select date_joined from auth_user where id = 6 ) as date_joined

from atencion_ciudadana_dependencia;


insert into atencion_ciudadana_dependencia_usuarios (dependencia_id, user_id)
select 
( select id from atencion_ciudadana_dependencia where lower(clave) = substring(username, 0,3) )
, id
from auth_user where last_name = 'Tabasco'


update auth_user
set password = (select password from auth_user where id = 6)
where last_name = 'Tabasco'

