@@ -1166,6 +1166,183 @@ public async Task Should_Preserve_Base_Model_Structure()
11661166
11671167 #endregion
11681168
1169+ #region Should_Remove_Internal_Sequences_When_No_Schema_Filter_Specified
1170+
1171+ private class InternalSeqHypertableMetric
1172+ {
1173+ public DateTime Timestamp { get ; set ; }
1174+ public double Value { get ; set ; }
1175+ }
1176+
1177+ private class InternalSeqHypertableContext ( string connectionString ) : DbContext
1178+ {
1179+ public DbSet < InternalSeqHypertableMetric > Metrics => Set < InternalSeqHypertableMetric > ( ) ;
1180+
1181+ protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
1182+ => optionsBuilder . UseNpgsql ( connectionString ) . UseTimescaleDb ( ) ;
1183+
1184+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
1185+ {
1186+ modelBuilder . Entity < InternalSeqHypertableMetric > ( entity =>
1187+ {
1188+ entity . HasNoKey ( ) ;
1189+ entity . ToTable ( "InternalSeqMetrics" ) ;
1190+ entity . IsHypertable ( x => x . Timestamp ) ;
1191+ } ) ;
1192+ }
1193+ }
1194+
1195+ [ Fact ]
1196+ public async Task Should_Remove_Internal_Sequences_When_No_Schema_Filter_Specified ( )
1197+ {
1198+ // Arrange
1199+ string testConnectionString = await GetTestConnectionStringAsync ( ) ;
1200+ await using InternalSeqHypertableContext context = new ( testConnectionString ) ;
1201+ await CreateDatabaseViaMigrationAsync ( context ) ;
1202+
1203+ TimescaleDatabaseModelFactory factory = CreateFactory ( ) ;
1204+ await using NpgsqlConnection connection = new ( testConnectionString ) ;
1205+
1206+ // Act
1207+ DatabaseModelFactoryOptions options = new ( tables : [ ] , schemas : [ ] ) ;
1208+ DatabaseModel model = factory . Create ( connection , options ) ;
1209+
1210+ // Assert
1211+ HashSet < string > internalSchemas =
1212+ [
1213+ "_timescaledb_internal" ,
1214+ "_timescaledb_catalog" ,
1215+ "_timescaledb_config" ,
1216+ "_timescaledb_cache"
1217+ ] ;
1218+
1219+ Assert . DoesNotContain ( model . Sequences , s => s . Schema != null && internalSchemas . Contains ( s . Schema ) ) ;
1220+ Assert . DoesNotContain ( model . Tables , t => t . Schema != null && internalSchemas . Contains ( t . Schema ) ) ;
1221+ }
1222+
1223+ #endregion
1224+
1225+ #region Should_Preserve_User_Sequences_When_No_Schema_Filter_Specified
1226+
1227+ private class UserSeqMetric
1228+ {
1229+ public DateTime Timestamp { get ; set ; }
1230+ public double Value { get ; set ; }
1231+ }
1232+
1233+ private class UserSeqEntity
1234+ {
1235+ public int Id { get ; set ; }
1236+ public string Name { get ; set ; } = string . Empty ;
1237+ }
1238+
1239+ private class UserSeqContext ( string connectionString ) : DbContext
1240+ {
1241+ public DbSet < UserSeqMetric > Metrics => Set < UserSeqMetric > ( ) ;
1242+ public DbSet < UserSeqEntity > Entities => Set < UserSeqEntity > ( ) ;
1243+
1244+ protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
1245+ => optionsBuilder . UseNpgsql ( connectionString ) . UseTimescaleDb ( ) ;
1246+
1247+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
1248+ {
1249+ modelBuilder . Entity < UserSeqMetric > ( entity =>
1250+ {
1251+ entity . HasNoKey ( ) ;
1252+ entity . ToTable ( "UserSeqMetrics" ) ;
1253+ entity . IsHypertable ( x => x . Timestamp ) ;
1254+ } ) ;
1255+
1256+ modelBuilder . Entity < UserSeqEntity > ( entity =>
1257+ {
1258+ entity . HasKey ( x => x . Id ) ;
1259+ entity . ToTable ( "UserSeqEntities" ) ;
1260+ } ) ;
1261+
1262+ modelBuilder . HasSequence < int > ( "user_explicit_seq" , "public" ) ;
1263+ }
1264+ }
1265+
1266+ [ Fact ]
1267+ public async Task Should_Preserve_User_Sequences_When_No_Schema_Filter_Specified ( )
1268+ {
1269+ // Arrange
1270+ string testConnectionString = await GetTestConnectionStringAsync ( ) ;
1271+ await using UserSeqContext context = new ( testConnectionString ) ;
1272+ await CreateDatabaseViaMigrationAsync ( context ) ;
1273+
1274+ TimescaleDatabaseModelFactory factory = CreateFactory ( ) ;
1275+ await using NpgsqlConnection connection = new ( testConnectionString ) ;
1276+
1277+ // Act
1278+ DatabaseModelFactoryOptions options = new ( tables : [ ] , schemas : [ ] ) ;
1279+ DatabaseModel model = factory . Create ( connection , options ) ;
1280+
1281+ // Assert
1282+ HashSet < string > internalSchemas =
1283+ [
1284+ "_timescaledb_internal" ,
1285+ "_timescaledb_catalog" ,
1286+ "_timescaledb_config" ,
1287+ "_timescaledb_cache"
1288+ ] ;
1289+
1290+ Assert . DoesNotContain ( model . Sequences , s => s . Schema != null && internalSchemas . Contains ( s . Schema ) ) ;
1291+ Assert . Contains ( model . Sequences , s => s . Name == "user_explicit_seq" && s . Schema == "public" ) ;
1292+ }
1293+
1294+ #endregion
1295+
1296+ #region Should_Not_Filter_Tables_Or_Sequences_When_Explicit_Schema_Filter_Is_Set
1297+
1298+ private class SchemaFilterMetric
1299+ {
1300+ public DateTime Timestamp { get ; set ; }
1301+ public double Value { get ; set ; }
1302+ }
1303+
1304+ private class SchemaFilterContext ( string connectionString ) : DbContext
1305+ {
1306+ public DbSet < SchemaFilterMetric > Metrics => Set < SchemaFilterMetric > ( ) ;
1307+
1308+ protected override void OnConfiguring ( DbContextOptionsBuilder optionsBuilder )
1309+ => optionsBuilder . UseNpgsql ( connectionString ) . UseTimescaleDb ( ) ;
1310+
1311+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
1312+ {
1313+ modelBuilder . Entity < SchemaFilterMetric > ( entity =>
1314+ {
1315+ entity . HasNoKey ( ) ;
1316+ entity . ToTable ( "SchemaFilterMetrics" , schema : "public" ) ;
1317+ entity . IsHypertable ( x => x . Timestamp ) ;
1318+ } ) ;
1319+ }
1320+ }
1321+
1322+ [ Fact ]
1323+ public async Task Should_Not_Filter_Tables_Or_Sequences_When_Explicit_Schema_Filter_Is_Set ( )
1324+ {
1325+ // Arrange
1326+ string testConnectionString = await GetTestConnectionStringAsync ( ) ;
1327+ await using SchemaFilterContext context = new ( testConnectionString ) ;
1328+ await CreateDatabaseViaMigrationAsync ( context ) ;
1329+
1330+ TimescaleDatabaseModelFactory factory = CreateFactory ( ) ;
1331+ await using NpgsqlConnection connection = new ( testConnectionString ) ;
1332+
1333+ // Act
1334+ DatabaseModelFactoryOptions options = new ( tables : [ ] , schemas : [ "public" ] ) ;
1335+ DatabaseModel model = factory . Create ( connection , options ) ;
1336+
1337+ // Assert
1338+ Assert . Contains ( model . Tables , t => t . Name == "SchemaFilterMetrics" && t . Schema == "public" ) ;
1339+ DatabaseTable ? metricsTable = model . Tables . FirstOrDefault ( t => t . Name == "SchemaFilterMetrics" ) ;
1340+ Assert . NotNull ( metricsTable ) ;
1341+ Assert . Equal ( true , metricsTable [ HypertableAnnotations . IsHypertable ] ) ;
1342+ }
1343+
1344+ #endregion
1345+
11691346 #region Should_Scaffold_Multiple_Continuous_Aggregates
11701347
11711348 private class MultiCaggSource
0 commit comments