9#ifndef MANTISBASE_ENTITY_SCHEMA_H
10#define MANTISBASE_ENTITY_SCHEMA_H
105 [[nodiscard]]
std::
string id() const;
111 [[nodiscard]]
std::
string name() const;
124 [[nodiscard]]
std::
string type() const;
137 [[nodiscard]]
bool hasApi() const;
156 [[nodiscard]]
bool isSystem() const;
231 [[nodiscard]]
bool hasField(const
std::
string &field_name) const;
269 [[nodiscard]]
std::
string toDDL() const;
286 [[nodiscard]]
std::
string dump() const;
388 static
std::
string getFieldType(const
std::
string &
type,
std::shared_ptr<
soci::session> sql,
391 void addFieldsIfNotExist(const
std::
string &
type);
395 std::
string m_viewSqlQuery;
396 bool m_isSystem = false;
397 bool m_hasApi = true;
401 MbAccessRule m_listRule, m_getRule, m_addRule, m_updateRule, m_deleteRule;
Access rule definition and shared evaluation for entity permissions.
Per-entity login method flags (password, OTP, OAuth).
MantisBase entry point.
Definition mantisbase.h:54
Access control rule for entity permissions.
Definition access_rules.h:45
MbAppMixin(const MantisBase &app)
Constrictor for instantiating this interface.
Definition types.cpp:5
Definition entity_schema_field.h:34
MbEntitySchema(MbEntitySchema &&) noexcept=default
MbEntitySchemaField & field(const std::string &field_name)
Get field by name (mutable reference).
Definition entity_schema.cpp:220
bool hasFieldById(const std::string &field_id) const
Check if field exists by ID.
Definition entity_schema.cpp:664
std::string dump() const
Dump schema as formatted string (for debugging).
Definition entity_schema.cpp:737
json toJSON() const
Convert schema to JSON representation.
Definition entity_schema.cpp:543
std::string toDDL() const
Generate SQL DDL (CREATE TABLE) statement.
Definition entity_schema.cpp:580
bool hasApi() const
Check if API endpoints are enabled.
Definition entity_schema.cpp:463
MbEntitySchema & addField(const MbEntitySchemaField &field)
Add a field to the schema (fluent interface).
Definition entity_schema.cpp:521
MbAccessRule deleteRule() const
Definition entity_schema.cpp:512
MbEntitySchemaField & fieldById(const std::string &field_id)
Get field by ID (mutable reference).
Definition entity_schema.cpp:233
MbEntitySchema & setDeleteRule(const MbAccessRule &deleteRule)
Definition entity_schema.cpp:514
const std::vector< IndexDefinition > & indexes() const
Definition entity_schema.cpp:285
MbEntitySchema & setAuthMethods(const MbAuthMethods &methods)
Definition entity_schema.cpp:467
static nlohmann::json getTable(const MantisBase &app, const std::string &table_id)
Get table schema by ID from database.
Definition entity_schema_crud.cpp:37
MbEntitySchema & setHasApi(const bool &hasApi)
Enable/disable API endpoints (fluent interface).
Definition entity_schema.cpp:472
static nlohmann::json createTable(const MbEntitySchema &new_table)
Create table in database from schema.
Definition entity_schema_crud.cpp:62
void updateWith(const nlohmann::json &new_data)
Update schema with new JSON data (merges fields).
Definition entity_schema.cpp:307
std::string type() const
Get entity type.
Definition entity_schema.cpp:442
static const std::vector< MbEntitySchemaField > & defaultBaseFieldsSchema()
Definition entity_schema_base_fields.cpp:9
MbEntitySchema & setUpdateRule(const MbAccessRule &updateRule)
Definition entity_schema.cpp:507
static std::string toDefaultSqlValue(const std::string &type, const nlohmann::json &v)
Get default SQL value for a field type.
Definition entity_schema.cpp:673
bool hasField(const std::string &field_name) const
Check if field exists by name.
Definition entity_schema.cpp:656
MbEntitySchema & setName(const std::string &name)
Set table name (fluent interface).
Definition entity_schema.cpp:437
MbEntitySchema & operator=(const MbEntitySchema &)
Definition entity_schema.cpp:27
MbAuthMethods authMethods() const
Definition entity_schema.cpp:465
MbEntitySchema & setListRule(const MbAccessRule &listRule)
Definition entity_schema.cpp:486
std::string name() const
Get table name.
Definition entity_schema.cpp:435
MbEntitySchema & setAddRule(const MbAccessRule &addRule)
Definition entity_schema.cpp:500
MbEntity toEntity() const
Convert schema to MbEntity for database operations.
Definition entity_schema.cpp:211
bool removeField(const std::string &field_name)
Remove a field by name.
Definition entity_schema.cpp:531
bool removeIndex(const std::string &index_name)
Definition entity_schema.cpp:298
static MbEntitySchema fromSchema(const MantisBase &app, const json &entity_schema)
Create schema from JSON object, bound to an application.
Definition entity_schema.cpp:71
static std::string genEntityId(const std::string &entity_name)
Generate unique entity ID from name.
Definition entity_schema.cpp:772
std::vector< std::string > indexDDL() const
Definition entity_schema.cpp:639
MbEntitySchema & setType(const std::string &type)
Set entity type (fluent interface).
Definition entity_schema.cpp:444
MbAccessRule listRule() const
Definition entity_schema.cpp:484
MbEntitySchema(const MantisBase &app)
Construct an empty schema bound to its application.
Definition entity_schema.cpp:9
bool isSystem() const
Check if this is a system table.
Definition entity_schema.cpp:477
static std::optional< std::string > validate(const MbEntitySchema &table_schema)
Validate schema (static method).
Definition entity_schema.cpp:776
static void dropTable(const MbEntitySchema &original_table)
Drop table from database.
Definition entity_schema_crud.cpp:757
MbEntitySchema & setViewQuery(const std::string &viewQuery)
Definition entity_schema.cpp:277
static const std::vector< MbEntitySchemaField > & defaultAuthFieldsSchema()
Definition entity_schema_base_fields.cpp:69
static bool isValidEntityType(const std::string &type)
Validate this schema type to the 3 supported types.
Definition entity_schema.cpp:872
static MbEntitySchema fromEntity(const MantisBase &app, const MbEntity &entity)
Create schema from existing MbEntity, bound to an application.
Definition entity_schema.cpp:162
MbAccessRule updateRule() const
Definition entity_schema.cpp:505
MbEntitySchema & addIndex(const IndexDefinition &index)
Definition entity_schema.cpp:289
MbEntitySchema & setGetRule(const MbAccessRule &getRule)
Definition entity_schema.cpp:493
static bool tableExists(const MantisBase &app, const std::string &table_name)
Check if table exists by name.
Definition entity_schema_crud.cpp:811
std::string viewQuery() const
Definition entity_schema.cpp:246
static nlohmann::json updateTable(const MantisBase &app, const std::string &table_id, const nlohmann::json &new_schema)
Update existing table schema in database.
Definition entity_schema_crud.cpp:135
static nlohmann::json listTables(const MantisBase &app, const nlohmann::json &opts=nlohmann::json::object())
List all tables from database.
Definition entity_schema_crud.cpp:14
MbAccessRule addRule() const
Definition entity_schema.cpp:498
static bool isValidEntityName(const std::string &name)
Validate this schema name to alphanum and _ only.
Definition entity_schema.cpp:879
std::vector< MbEntitySchemaField > fields() const
Get all field definitions.
Definition entity_schema.cpp:519
MbEntitySchema & setSystem(const bool &isSystem)
Set system table flag (fluent interface).
Definition entity_schema.cpp:479
MbAccessRule getRule() const
Definition entity_schema.cpp:491
MbEntitySchema(const MbEntitySchema &)
Represents a database table/entity with schema and CRUD operations.
Definition entity.h:55
MbEntity class for database table operations and CRUD functionality.
MbEntity schema field definition and validation.
#define MANTISBASE_API
Definition export.h:31
nlohmann::json json
Shorten JSON namespace.
Definition api_keys.h:36
MbIntPrecision
Definition int_precision.h:24
Definition log_database.h:21
Definition entity_schema_field.h:22
Definition auth_methods.h:21
Core type aliases, handler signatures, and the MbAppMixin DI mixin.