Checking if a table exists during plugin installation

3 months ago
When a plugin is uninstalled, tables created by that plugin may not be deleted. This can cause a problem when reinstalling the plugin. For this reason I want to check if the table exists in database during plugin installation. If the table from previous installation is exist, it shouldn't try to create new one.
I saw some old topics about this but I couldn't achive to run Sql commands in order to perform the check before table creation. Which way or service should I use?

NopCommerce Version is 4.80.
Server is Microsoft Sql Server.
It runs in my local network.

This is my SchemeMigration.cs file:
[NopMigration("2025-01-21 17:07:00:1111111", "Create NotificationBar", MigrationProcessType.Installation)]
public class SchemeMigration : Migration //AutoReversingMigration
{
    protected readonly IMigrationManager _migrationManager;

    public SchemeMigration(IMigrationManager migrationManager)
    {
        _migrationManager = migrationManager;
    }

    public override void Up()
{
// Here, check if the table already exists
Create.TableFor<QuestionEntity>();
}
    public override void Down()
    {
        Delete.Table("Question");
    }
    
3 months ago

public override void Up()
{
    if (!DataSettingsManager.IsDatabaseInstalled())    
        return;

    var tableName = NameCompatibilityManager.GetTableName(typeof(QuestionEntity));

    if (!Schema.Table(tableName).Exists())
        Create.TableFor<QuestionEntity>();
}