createSampleConfig static method
Creates a sample configuration file (supabase_gen.yaml) at the specified filePath.
This sample includes sections for database connection, general generation settings, model generation, and Drift migration generation settings.
Throws a FileSystemException if a file already exists at the path.
Implementation
static Future<void> createSampleConfig(String filePath) async {
final file = File(filePath);
if (await file.exists()) {
// Use await file.exists() for async check
print(
'Warning: Configuration file already exists at $filePath. Not overwriting.',
);
// Or throw: throw FileSystemException('Configuration file already exists', filePath);
return;
}
try {
// Ensure the directory for the config file exists
final parentDir = file.parent;
if (!await parentDir.exists()) {
await parentDir.create(recursive: true);
}
// Updated sample config content
const String sampleConfigContent = """
database:
host: TETHER_SUPABASE_HOST
port: TETHER_PORT_NAME
database: TETHER_DB_NAME
username: TETHER_DB_USERNAME
password: TETHER_DB_PASSWORD
ssl: TETHER_SSL
generation:
output_directory: lib/database
exclude_tables:
- migrations
- schema_migrations
include_tables: []
exclude_references: []
generate_for_all_tables: true
dbClassName: AppDb
databaseName: 'app_db.sqlite'
models:
enabled: true
filename: models.g.dart
prefix: ''
suffix: Model
use_null_safety: true
supabase_select_builders:
enabled: true
filename: 'supabase_select_builders.g.dart'
generated_schema_dart_file_name: 'supabase_schema.g.dart'
suffix: SelectBuilder
schema_registry_file_name: 'schema_registry.g.dart'
sqlite_migrations:
enabled: true
output_subdir: 'sqlite_migrations'
client_managers:
enabled: true
use_riverpod: true
providers:
enabled: true
output_subdir: 'providers'
authentication:
enabled: true
profile_table: 'profiles'
background_services:
enabled: true
sanitization_endings:
- _id
- _fk
- _uuid
""";
await file.writeAsString(sampleConfigContent);
print(
'Sample configuration file (referencing .env variables) created at: $filePath',
);
print(
'Please ensure you have a .env file with your actual database credentials.',
);
} catch (e) {
print('Error creating sample configuration file at $filePath: $e');
}
}