#include "components/affiliations/core/browser/sql_table_builder.h"
#include <set>
#include <string_view>
#include <utility>
#include "base/containers/adapters.h"
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "sql/database.h"
#include "sql/statement.h"
#include "sql/transaction.h"
namespace affiliations {
namespace {
void Append(const std::string& name, std::string* list_of_names) { … }
bool CheckForeignKeyConstraints(sql::Database& db) { … }
std::string ComputeColumnSuffix(bool is_primary_key,
const std::string& parent_table) { … }
}
unsigned constexpr SQLTableBuilder::kInvalidVersion;
struct SQLTableBuilder::Column { … };
struct SQLTableBuilder::Index { … };
SQLTableBuilder::SQLTableBuilder(const std::string& table_name)
: … { … }
SQLTableBuilder::~SQLTableBuilder() = default;
void SQLTableBuilder::AddColumn(std::string name, std::string type) { … }
void SQLTableBuilder::AddPrimaryKeyColumn(std::string name) { … }
void SQLTableBuilder::AddColumnToUniqueKey(std::string name, std::string type) { … }
void SQLTableBuilder::AddColumnToUniqueKey(std::string name,
std::string type,
std::string parent_table,
std::string index_name) { … }
void SQLTableBuilder::RenameColumn(const std::string& old_name,
const std::string& new_name) { … }
void SQLTableBuilder::DropColumn(const std::string& name) { … }
void SQLTableBuilder::AddIndex(std::string name,
std::vector<std::string> columns) { … }
std::string SQLTableBuilder::ComputeConstraints(unsigned version) const { … }
unsigned SQLTableBuilder::SealVersion() { … }
bool SQLTableBuilder::MigrateFrom(
unsigned old_version,
sql::Database* db,
const base::RepeatingCallback<bool(sql::Database*, unsigned)>&
post_migration_step_callback) const { … }
bool SQLTableBuilder::CreateTable(sql::Database* db) const { … }
std::string SQLTableBuilder::ListAllColumnNames() const { … }
std::string SQLTableBuilder::ListAllNonuniqueKeyNames() const { … }
std::string SQLTableBuilder::ListAllUniqueKeyNames() const { … }
std::vector<std::string_view> SQLTableBuilder::AllPrimaryKeyNames() const { … }
size_t SQLTableBuilder::NumberOfColumns() const { … }
std::string SQLTableBuilder::TableName() const { … }
bool SQLTableBuilder::MigrateToNextFrom(unsigned old_version,
sql::Database* db) const { … }
bool SQLTableBuilder::MigrateIndicesToNextFrom(unsigned old_version,
sql::Database* db) const { … }
std::vector<SQLTableBuilder::Column>::reverse_iterator
SQLTableBuilder::FindLastColumnByName(const std::string& name) { … }
std::vector<SQLTableBuilder::Index>::reverse_iterator
SQLTableBuilder::FindLastIndexByName(const std::string& name) { … }
bool SQLTableBuilder::IsVersionLastAndSealed(unsigned version) const { … }
bool SQLTableBuilder::IsColumnInLastVersion(const Column& column) const { … }
bool SQLTableBuilder::IsIndexInLastVersion(const Index& index) const { … }
}