public void No_PrimaryKey() { var c = new Constraint("ix_testing", ContraintType.Index, "testing"); var test = new Table("test"); test.Constraints.Add(c); Assert.Null(test.PrimaryKey); }
public void Create_Column() { var c = new Column("testing", ColumnTypes.Bigint, true); var test = new Table("test"); test.Columns.Add(c); Assert.True(test.Columns.Items.Any(item => item.Name == "testing")); }
public void Set_PrimaryKey() { var c = new Constraint("ix_testing", ContraintType.PrimaryKey, "testing"); var test = new Table("test"); test.Constraints.Add(c); Assert.Equal(c, test.PrimaryKey); }
/// <summary> /// Creates the main table schema /// </summary> /// <returns></returns> private Table CreateMainTable() { //--main table-- var main = new Table(_tableNameHelper.JobTableName); main.Columns.Add(new Column("JobEventTime", ColumnTypes.Bigint, false)); main.Columns.Add(new Column("JobScheduledTime", ColumnTypes.Bigint, false)); main.Columns.Add(new Column("JobName", ColumnTypes.Varchar, 255, false)); //add primary key constraint main.Constraints.Add(new Constraint("PK_" + _tableNameHelper.JobTableName, ContraintType.PrimaryKey, "JobName")); main.PrimaryKey.Unique = true; return main; }
public void Create_Script() { var c = new Column("testing", ColumnTypes.Bigint, true); var cc = new Constraint("ix_testing", ContraintType.Index, "testing"); var test = new Table("test"); test.Constraints.Add(cc); test.Columns.Add(c); //set the table reference foreach (var ccc in test.Constraints) { ccc.Table = test.Info; } Assert.Contains("test", test.Script()); }
/// <summary> /// Creates the main table schema /// </summary> /// <returns></returns> private Table CreateMainTable() { //--main data table-- var main = new Table(_tableNameHelper.QueueName); var mainPrimaryKey = new Column("QueueID", ColumnTypes.Bigint, false) {Identity = true}; main.Columns.Add(mainPrimaryKey); main.Columns.Add(new Column("Body", ColumnTypes.Bytea, -1, false)); main.Columns.Add(new Column("Headers", ColumnTypes.Bytea, -1, false)); //add primary key constraint main.Constraints.Add(new Constraint("PK_" + _tableNameHelper.QueueName, ContraintType.PrimaryKey, "QueueID")); main.PrimaryKey.Unique = true; return main; }
public void GetSet_Name() { var test = new Table("test") {Name = "test1"}; Assert.Equal("test1", test.Name); }
public void No_PrimaryKey2() { var test = new Table("test"); Assert.Null(test.PrimaryKey); }
public void Default() { var test = new Table("test"); Assert.Equal("test", test.Name); }
/// <summary> /// Creates the configuration table schema. /// </summary> /// <returns></returns> private Table CreateConfigurationTable() { var table = new Table(_tableNameHelper.ConfigurationName); var mainPrimaryKey = new Column("ID", ColumnTypes.Integer, false) {Identity = true}; table.Columns.Add(mainPrimaryKey); table.Columns.Add(new Column("Configuration", ColumnTypes.Bytea, -1, false)); table.Constraints.Add(new Constraint("PK_" + _tableNameHelper.ConfigurationName, ContraintType.PrimaryKey, "ID")); table.PrimaryKey.Unique = true; return table; }
/// <summary> /// Creates the error table schema. This is a copy of the meta table, but with an exception column added. /// </summary> /// <param name="meta">The meta.</param> /// <returns></returns> private Table CreateErrorTable(Table meta) { var metaErrors = new Table(_tableNameHelper.MetaDataErrorsName); var primaryKey = new Column("ID", ColumnTypes.Bigint, false) {Identity = true}; metaErrors.Columns.Add(primaryKey); foreach (var c in meta.Columns.Items) { metaErrors.Columns.Add(c.Clone()); } metaErrors.Columns.Add(new Column("LastException", ColumnTypes.Text, -1, true)); metaErrors.Columns.Add(new Column("LastExceptionDate", ColumnTypes.Timestamp, true)); //add primary key constraint metaErrors.Constraints.Add(new Constraint("PK_" + _tableNameHelper.MetaDataErrorsName, ContraintType.PrimaryKey, "ID")); metaErrors.PrimaryKey.Unique = true; //NOTE no indexes are copied from the meta table foreach (var c in metaErrors.Constraints) { c.Table = metaErrors.Info; } return metaErrors; }
/// <summary> /// Creates the error tracking table schema. /// </summary> /// <returns></returns> private Table CreateErrorTrackingTable() { //--Error tracking table-- var errorTracking = new Table(_tableNameHelper.ErrorTrackingName); var errorTrackingPrimaryKey = new Column("ErrorTrackingID", ColumnTypes.Bigint, false) { Identity = true }; errorTracking.Columns.Add(errorTrackingPrimaryKey); errorTracking.Columns.Add(new Column("QueueID", ColumnTypes.Bigint, false)); errorTracking.Columns.Add(new Column("ExceptionType", ColumnTypes.Varchar, 500, false)); errorTracking.Columns.Add(new Column("RetryCount", ColumnTypes.Integer, false)); //add primary key constraint errorTracking.Constraints.Add(new Constraint("PK_" + _tableNameHelper.ErrorTrackingName, ContraintType.PrimaryKey, "ErrorTrackingID")); errorTracking.PrimaryKey.Unique = true; errorTracking.Constraints.Add(new Constraint($"IX_QueueID{_tableNameHelper.ErrorTrackingName}", ContraintType.Index, "QueueID")); foreach (var c in errorTracking.Constraints) { c.Table = errorTracking.Info; } return errorTracking; }
/// <summary> /// Creates the meta data table schema. /// </summary> /// <returns></returns> private Table CreateMetaDataTable() { //--Meta Data Table -- var meta = new Table(_tableNameHelper.MetaDataName); var mainPrimaryKey = new Column("QueueID", ColumnTypes.Bigint, false); meta.Columns.Add(mainPrimaryKey); //add primary key constraint meta.Constraints.Add(new Constraint("PK_" + _tableNameHelper.MetaDataName, ContraintType.PrimaryKey, "QueueID")); meta.PrimaryKey.Unique = true; if (_options.Value.EnablePriority) { meta.Columns.Add(new Column("Priority", ColumnTypes.Integer, false)); } meta.Columns.Add(new Column("QueuedDateTime", ColumnTypes.Timestamp, false)); if (_options.Value.EnableStatus) { meta.Columns.Add(new Column("Status", ColumnTypes.Integer, false)); } if (_options.Value.EnableDelayedProcessing) { meta.Columns.Add(new Column("QueueProcessTime", ColumnTypes.Bigint, false)); } meta.Columns.Add(new Column("CorrelationID", ColumnTypes.Uuid, false)); if (_options.Value.EnableHeartBeat) { meta.Columns.Add(new Column("HeartBeat", ColumnTypes.Bigint, true)); } if (_options.Value.EnableRoute) { meta.Columns.Add(new Column("Route", ColumnTypes.Text, 255, true)); } if (_options.Value.EnableMessageExpiration || _options.Value.QueueType == QueueTypes.RpcReceive || _options.Value.QueueType == QueueTypes.RpcSend) { meta.Columns.Add(new Column("ExpirationTime", ColumnTypes.Bigint, false)); } switch (_options.Value.QueueType) { case QueueTypes.RpcReceive: meta.Columns.Add(new Column("SourceQueueID", ColumnTypes.Bigint, false)); break; } var clusterIndex = new List<string>(); if (_options.Value.EnableStatus) { clusterIndex.Add("Status"); } if (_options.Value.EnablePriority) { clusterIndex.Add("Priority"); } if (_options.Value.EnableDelayedProcessing) { clusterIndex.Add("QueueProcessTime"); } if (_options.Value.EnableRoute) { clusterIndex.Add("Route"); } //add index on expiration time if needed if (_options.Value.EnableMessageExpiration || _options.Value.QueueType == QueueTypes.RpcReceive || _options.Value.QueueType == QueueTypes.RpcSend) { clusterIndex.Add("ExpirationTime"); } switch (_options.Value.QueueType) { case QueueTypes.RpcReceive: clusterIndex.Add("SourceQueueID"); break; } if (clusterIndex.Count > 0) { clusterIndex.Add("QueueID"); } if (clusterIndex.Count > 0) { var cluster = new Constraint($"IX_DeQueue{_tableNameHelper.MetaDataName}", ContraintType.Index, clusterIndex) { Unique = true }; meta.Constraints.Add(cluster); } //add index on heartbeat column if enabled if (_options.Value.EnableHeartBeat) { meta.Constraints.Add(new Constraint($"IX_HeartBeat{_tableNameHelper.MetaDataName}", ContraintType.Index, "HeartBeat")); } //set the table reference foreach (var c in meta.Constraints) { c.Table = meta.Info; } return meta; }
private Table CreateStatusTable() { //--Meta Data Table -- var status = new Table(_tableNameHelper.StatusName); var mainPrimaryKey = new Column("QueueID", ColumnTypes.Bigint, false); status.Columns.Add(mainPrimaryKey); //add primary key constraint status.Constraints.Add(new Constraint("PK_" + _tableNameHelper.StatusName, ContraintType.PrimaryKey, "QueueID")); status.PrimaryKey.Unique = true; status.Columns.Add(new Column("Status", ColumnTypes.Integer, false)); status.Columns.Add(new Column("CorrelationID", ColumnTypes.Uuid, false)); //add extra user columns foreach (var c in _options.Value.AdditionalColumns.Values) { status.Columns.Add(c); } //add extra user constrains foreach (var c in _options.Value.AdditionalConstraints.Values) { status.Constraints.Add(c); } //set the table reference foreach (var c in status.Constraints) { c.Table = status.Info; } return status; }