hasTable(self::RESOURCES_TABLE)) { $table = $schema->createTable(self::RESOURCES_TABLE); $table->addColumn('id', Types::INTEGER, [ 'autoincrement' => true, 'notnull' => true, ]); $table->addColumn('parent_resource', Types::INTEGER, [ 'notnull' => false, ]); $table->addColumn('organization_folder_id', Types::BIGINT, [ 'length' => 20, 'notnull' => true, ]); $table->addColumn('type', Types::STRING, [ 'length' => 20, 'notnull' => true, ]); $table->addColumn('name', Types::STRING, [ 'length' => 64, 'notnull' => true, ]); $table->addColumn('active', Types::BOOLEAN, [ 'notnull' => true, ]); $table->addColumn('last_updated_timestamp', Types::BIGINT, [ 'notnull' => true, ]); $table->setPrimaryKey(['id']); $table->addForeignKeyConstraint( $table, ['parent_resource'], ['id'], ['onDelete' => 'CASCADE'], 'organizationfolders_resources_parent_resource_id_fk'); $table->addForeignKeyConstraint( $schema->getTable(self::GROUP_FOLDERS_TABLE), ['organization_folder_id'], ['folder_id'], ['onDelete' => 'CASCADE'], 'organizationfolders_resources_organization_folder_id_fk'); // WARNING: CONSTRAINT CURRENTLY DOES NOT WORK FOR TOP LEVEL RESOURCES, AS ROWS WITH A NULL IN ONE OF THE UNIQUE COLUMNS WILL NOT BE CHECKED BY THIS // TODO: use NULLS NOT DISTINCT (postgres supported only) $table->addUniqueConstraint(['organization_folder_id', 'parent_resource', 'name'], "organizationfolders_resources_name_unique"); } if (!$schema->hasTable(self::FOLDER_RESOURCES_TABLE)) { $table = $schema->createTable(self::FOLDER_RESOURCES_TABLE); $table->addColumn('resource_id', Types::INTEGER, [ 'notnull' => true, ]); $table->addColumn('members_acl_permission', Types::INTEGER, [ 'length' => 11, 'notnull' => true, ]); $table->addColumn('managers_acl_permission', Types::INTEGER, [ 'length' => 11, 'notnull' => true, ]); $table->addColumn('inherited_acl_permission', Types::INTEGER, [ 'length' => 11, 'notnull' => true, ]); $table->setPrimaryKey(['resource_id']); $table->addForeignKeyConstraint( $schema->getTable(self::RESOURCES_TABLE), ['resource_id'], ['id'], ['onDelete' => 'CASCADE'], 'organizationfolders_folder_resources_resource_id_fk'); } return $schema; } }