-- SETUP/RESTORE USERS IF OTHER DATABASES ARE PRESENT

USE [VIGIL-Settings]
GO

IF EXISTS (SELECT * FROM sys.databases WHERE name=N'VIGIL-DVR')
BEGIN
	CREATE USER [vigil] FOR LOGIN [vigil]
	ALTER ROLE [db_owner] ADD MEMBER [vigil]

	EXEC [VIGIL-DVR]..sp_executesql N'IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N''settings'') DROP USER [settings]'
	EXEC [VIGIL-DVR]..sp_executesql N'CREATE USER [settings] FOR LOGIN [settings]'
	EXEC [VIGIL-DVR]..sp_executesql N'ALTER ROLE [db_datareader] ADD MEMBER [settings]'
END
GO


-- MISC. FINAL ACTIONS

USE [master]
GO

ALTER DATABASE [VIGIL-Settings] SET  READ_WRITE 
GO
