When a new database is created in a cluster, the config server writes an entry for it to config.databases through ConfigSvrCreateDatabaseCommand -> ShardingCatalogManager::createDatabase().
If the config server is in fcv>=4.0, it should generate a databaseVersion for the new database and include it in the config.databases entry.