This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement; // nuget package | |
using System; | |
using System.Configuration; | |
using System.Data.Common; | |
using System.Data.SqlClient; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace ISharded.Data | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Create EF context that will connect to Azure shard. | |
/// </summary> | |
/// <param name="operational">True if connecting for operational data (as opposed to historical). My solution only contains 2 shards so I can use bool. This could, for instance, simply be the integer parameter of the needed shard.</param> | |
public ShardContext(bool operational) : base(ShardManagement.GetRegularConnection(operational), true) | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ShardManagement.TrySetShardMapManager(); | |
// true in this sample means first shard (operational). | |
using (var context = new ShardContext(true)) | |
{ | |
var customer = context.Customers.FirstOrDefault(); | |
if (customer != null) | |
{ | |
Console.WriteLine($"First operational customer: {customer.CustomerId}"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------- Create a regular Table for Demo ------------------------------------------------------------------------ | |
-- Adapted from https://www.mssqltips.com/sqlservertip/2888/how-to-partition-an-existing-sql-server-table/ | |
--Table/Index creation. Create table as it would exist before partitioning. | |
CREATE TABLE [dbo].[TABLE1] | |
([pkcol] [int] NOT NULL, | |
[datacol] [int] NULL, | |
[partitioncol] datetime) | |
GO | |
ALTER TABLE dbo.TABLE1 ADD CONSTRAINT PK_TABLE1 PRIMARY KEY CLUSTERED (pkcol) | |
GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------- Change database name [Sandbox] to whatever you please (or create it) ------------------------------------------ | |
---------------------------------- Change paths to files below to whatever you please. ------------------------------------------ | |
---------------------------------- Cleanup shrinkfile commands at very bottom assume file names as well. ------------------------------------------ | |
---------------------------------- Create Files/File Groups ------------------------------------------------------------------------- | |
-- We will want 2 new filegroups/files four our partitions: | |
-- PRIMARY: Partition 2; operational data | |
-- History: Partition 1; historical data | |
-- Split: Partition N; temp during split/merge of partitions. | |
ALTER DATABASE [Sandbox] ADD FILEGROUP [History] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Helper function. Drop If Exists depends on v16. | |
drop function if exists RemoveLeadingTuple; | |
go | |
create function RemoveLeadingTuple(@s varchar(max)) returns varchar(max) as | |
-- If @s contains a leading tuple, e.g., '((xx))', remove the string with that tuple removed | |
begin | |
declare @result varchar(max) = @s; | |
declare @leftParens int = 0; | |
declare @rightParens int = 0; | |
if (LEFT(@s, 1) = '(') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CypressCommand = 'npx cypress run --spec ' + "'" + $('$(Build.SourcesDirectory)').Replace('\', '/') + '/AutomatedTests/Cypress/cypress/integration/ci_test.js' + "'" | |
Invoke-Expression $CypressCommand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function GetPartitionQueryDate() returns date as | |
-- Provides the date that we will always query partitioned tables on. | |
-- Dates within the past 90 days should always be in the operational partition of any partitioned table. | |
begin | |
return GETDATE() - 90 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Show partition row counts | |
SELECT $PARTITION.PartitionTable_PartitionFunc(PartitionedColumn) as Partition_Number, COUNT(1) as Row_Count | |
FROM PartionedTable | |
GROUP BY $PARTITION.order_PartitionFunc(PartitionedColumn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"valueParameterInfo":[],"slotParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"","contractName":"","contractLongDescription":"","choiceInfo":[]} |
OlderNewer