text: /*
  Implementation notes:
  
  1) The general idea is that data is read and written through Orleans specific queries.
     Orleans operates on column names and types when reading and on parameter names and types when writing.
  
  2) The implementations *must* preserve input and output names and types. Orleans uses these parameters to reads query results by name and type.
     Vendor and deployment specific tuning is allowed and contributions are encouraged as long as the interface contract
     is maintained.
  
  3) The implementation across vendor specific scripts *should* preserve the constraint names. This simplifies troubleshooting
     by virtue of uniform naming across concrete implementations.
  
  5) ETag for Orleans is an opaque column that represents a unique version. The type of its actual implementation
     is not important as long as it represents a unique version. In this implementation we use integers for versioning
  
  6) For the sake of being explicit and removing ambiguity, Orleans expects some queries to return either TRUE as >0 value
     or FALSE as =0 value. That is, affected rows or such does not matter. If an error is raised or an exception is thrown
     the query *must* ensure the entire transaction is rolled back and may either return FALSE or propagate the exception.
     Orleans handles exception as a failure and will retry.
  
  7) The implementation follows the Extended Orleans membership protocol. For more information, see at:
  		http://dotnet.github.io/orleans/Runtime-Implementation-Details/Runtime-Tables.html
  		http://dotnet.github.io/orleans/Runtime-Implementation-Details/Cluster-Management
  		https://github.com/dotnet/orleans/blob/master/src/Orleans/SystemTargetInterfaces/IMembershipTable.cs
  */
  
  -- These settings improves throughput of the database by reducing locking by better separating readers from writers.
  -- SQL Server 2012 and newer can refer to itself as CURRENT. Older ones need a workaround.
  USE Orleans
  GO
  
  DECLARE @current NVARCHAR(256);
  DECLARE @snapshotSettings NVARCHAR(612);
  
  SELECT @current = (SELECT DB_NAME());
  SET @snapshotSettings = N'ALTER DATABASE ' + @current + N' SET READ_COMMITTED_SNAPSHOT ON; ALTER DATABASE ' + @current + N' SET ALLOW_SNAPSHOT_ISOLATION ON;';
  
  EXECUTE sp_executesql @snapshotSettings;
  
  -- This table defines Orleans operational queries. Orleans uses these to manage its operations,
  -- these are the only queries Orleans issues to the database.
  -- These can be redefined (e.g. to provide non-destructive updates) provided the stated interface principles hold.
  CREATE TABLE OrleansQuery
  (
  	QueryKey VARCHAR(64) NOT NULL,
  	QueryText VARCHAR(8000) NOT NULL,
  
  	CONSTRAINT OrleansQuery_Key PRIMARY KEY(QueryKey)
  );
  GO
  