if not exists (select top 1 1 from sys.objects where name = 'ActivityLog' and type = 'U')
begin
	create table ActivityLog
	(
		ActivityLogId int identity(1, 1) constraint PK_ActivityLog primary key,
		MachineId int constraint FK_ActivityLog_Machine foreign key references Machine(MachineId),
		UserId int not null,
		ActivityId int constraint FK_ActivityLog_PowerAction foreign key references PowerAction(PowerActionId),
		ActivityDate datetime not null,
		Success bit not null,
		Details varchar(2000)
	)
end
go

if not exists (select top 1 1 from sys.objects where name = 'MachineCounters' and type = 'U')
begin
	create table MachineCounters
	(
		MachineId int constraint FK_MachineCounters_Machine foreign key references Machine(MachineId),
		ActivityId int constraint FK_MachineCounters_PowerAction foreign key references PowerAction(PowerActionId),
		[Counter] int not null
	)
end
go