Skip to content

Feature mysql driver support #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ public function configuration(): BelongsTo
foreignKey: 'account_configuration_id',
);
}

protected function getCastMap(): array
{
return [
'account_verified_at' => 'datetime',
'stripe_connect_setup_complete' => 'boolean',
'is_manually_verified' => 'boolean',
];
}
}
1 change: 1 addition & 0 deletions backend/app/Models/AccountConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AccountConfiguration extends BaseModel
protected function getCastMap(): array
{
return [
'is_system_default' => 'boolean',
'application_fees' => 'array',
];
}
Expand Down
7 changes: 7 additions & 0 deletions backend/app/Models/AccountUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

protected function getCastMap(): array
{
return [
'is_account_owner' => 'boolean',
];
}
}
7 changes: 7 additions & 0 deletions backend/app/Models/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ public function check_in(): HasOne
{
return $this->hasOne(AttendeeCheckIn::class);
}

public function getCastMap(): array
{
return [
'checked_in_at' => 'datetime',
];
}
}
8 changes: 8 additions & 0 deletions backend/app/Models/CheckInList.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}

public function getCastMap(): array
{
return [
'expires_at' => 'datetime',
'activates_at' => 'datetime',
];
}
}
10 changes: 10 additions & 0 deletions backend/app/Models/EventSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ protected function getCastMap(): array
return [
'location_details' => 'array',
'payment_providers' => 'array',
'social_media_handles' => 'array',
'show_share_buttons' => 'boolean',
'hide_getting_started_page' => 'boolean',
'is_online_event' => 'boolean',
'notify_organizer_of_new_orders' => 'boolean',
'require_attendee_details' => 'boolean',
'require_billing_address' => 'boolean',
'allow_orders_awaiting_offline_payment_to_check_in' => 'boolean',
'enable_invoicing' => 'boolean',
'allow_search_engine_indexing' => 'boolean',
];
}
}
1 change: 1 addition & 0 deletions backend/app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function getCastMap(): array
'attendee_ids' => 'array',
'product_ids' => 'array',
'send_data' => 'array',
'sent_at' => 'datetime',
];
}
}
2 changes: 2 additions & 0 deletions backend/app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ protected function getCastMap(): array
'point_in_time_data' => 'array',
'address' => 'array',
'taxes_and_fees_rollup' => 'array',
'is_manually_created' => 'boolean',
'reserved_until' => 'datetime',
];
}

Expand Down
1 change: 1 addition & 0 deletions backend/app/Models/OrderApplicationFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected function getCastMap(): array
{
return [
'metadata' => 'array',
'paid_at' => 'datetime',
];
}

Expand Down
9 changes: 9 additions & 0 deletions backend/app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ protected function getCastMap(): array
return [
ProductDomainObjectAbstract::SALES_VOLUME => 'float',
ProductDomainObjectAbstract::SALES_TAX_VOLUME => 'float',
ProductDomainObjectAbstract::HIDE_BEFORE_SALE_START_DATE => 'boolean',
ProductDomainObjectAbstract::HIDE_AFTER_SALE_END_DATE => 'boolean',
ProductDomainObjectAbstract::HIDE_WHEN_SOLD_OUT => 'boolean',
ProductDomainObjectAbstract::SHOW_QUANTITY_REMAINING => 'boolean',
ProductDomainObjectAbstract::IS_HIDDEN_WITHOUT_PROMO_CODE => 'boolean',
ProductDomainObjectAbstract::IS_HIDDEN => 'boolean',
ProductDomainObjectAbstract::START_COLLAPSED => 'boolean',
ProductDomainObjectAbstract::SALE_START_DATE => 'datetime',
ProductDomainObjectAbstract::SALE_END_DATE => 'datetime',
];
}

Expand Down
7 changes: 7 additions & 0 deletions backend/app/Models/ProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class ProductCategory extends BaseModel
'event_id',
];

protected function getCastMap(): array
{
return [
'is_hidden' => 'boolean',
];
}

public function products(): HasMany
{
return $this->hasMany(Product::class);
Expand Down
3 changes: 3 additions & 0 deletions backend/app/Models/ProductPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ protected function getCastMap(): array
{
return [
'price' => 'float',
'sale_start_date' => 'datetime',
'sale_end_date' => 'datetime',
'is_hidden' => 'boolean',
];
}

Expand Down
2 changes: 2 additions & 0 deletions backend/app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ protected function getCastMap(): array
{
return [
QuestionDomainObjectAbstract::OPTIONS => 'array',
QuestionDomainObjectAbstract::REQUIRED => 'boolean',
QuestionDomainObjectAbstract::IS_HIDDEN => 'boolean',
];
}

Expand Down
2 changes: 2 additions & 0 deletions backend/app/Models/TaxAndFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ protected function getCastMap(): array
{
return [
'rate' => 'float',
'is_active' => 'boolean',
'is_default' => 'boolean',
];
}
}
1 change: 1 addition & 0 deletions backend/app/Models/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function getCastMap(): array
{
return [
'event_types' => 'array',
'last_triggered_at' => 'datetime',
];
}

Expand Down
6 changes: 3 additions & 3 deletions backend/app/Repository/Eloquent/CheckInListRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getCheckedInAttendeeCountById(int $checkInListId): CheckedInAtte
JOIN event_settings es ON cil.event_id = es.event_id
WHERE a.deleted_at IS NULL
AND pcil.deleted_at IS NULL
AND pcil.check_in_list_id = :check_in_list_id
AND pcil.check_in_list_id = :check_in_list_id2
AND (
(es.allow_orders_awaiting_offline_payment_to_check_in = true AND a.status in ('ACTIVE', 'AWAITING_PAYMENT') AND o.status IN ('COMPLETED', 'AWAITING_OFFLINE_PAYMENT'))
OR
Expand All @@ -58,12 +58,12 @@ public function getCheckedInAttendeeCountById(int $checkInListId): CheckedInAtte
FROM check_in_lists cil
LEFT JOIN valid_attendees va ON va.check_in_list_id = cil.id
LEFT JOIN valid_check_ins vci ON vci.attendee_id = va.id
WHERE cil.id = :check_in_list_id
WHERE cil.id = :check_in_list_id3
AND cil.deleted_at IS NULL
GROUP BY cil.id;
SQL;

$query = $this->db->selectOne($sql, ['check_in_list_id' => $checkInListId]);
$query = $this->db->selectOne($sql, ['check_in_list_id' => $checkInListId, 'check_in_list_id2' => $checkInListId, 'check_in_list_id3' => $checkInListId]);

return new CheckedInAttendeesCountDTO(
checkInListId: $checkInListId,
Expand Down
72 changes: 53 additions & 19 deletions backend/app/Repository/Eloquent/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use RuntimeException;
use Throwable;

Expand Down Expand Up @@ -72,13 +73,14 @@ public function getQuantityRemainingForProductPrice(int $productId, int $product
) AS quantity_remaining,
product_prices.initial_quantity_available IS NULL AS unlimited_products_available
FROM product_prices
WHERE product_prices.id = :productPriceId
WHERE product_prices.id = :productPriceId2
AND product_prices.product_id = :productId
AND product_prices.deleted_at IS NULL
SQL;

$result = $this->db->selectOne($query, [
'productPriceId' => $productPriceId,
'productPriceId2' => $productPriceId,
'productId' => $productId
]);

Expand All @@ -90,7 +92,7 @@ public function getQuantityRemainingForProductPrice(int $productId, int $product
return Constants::INFINITE;
}

return (int)$result->quantity_remaining;
return (int) $result->quantity_remaining;
}

public function getTaxesByProductId(int $productId): Collection
Expand Down Expand Up @@ -203,14 +205,30 @@ public function bulkUpdateProductsAndCategories(int $eventId, array $productUpda
$productOrders = range(1, count($productUpdates));
$productCategoryIds = array_column($productUpdates, 'product_category_id');

$productParameters = [
'eventId' => $eventId,
'productIds' => '{' . implode(',', $productIds) . '}',
'productOrders' => '{' . implode(',', $productOrders) . '}',
'productCategoryIds' => '{' . implode(',', $productCategoryIds) . '}',
];

$productUpdateQuery = "WITH new_order AS (
if (DB::getDriverName() === 'mysql') {
for ($i = 0; $i < count($productIds); $i++) {
$this->db->update("UPDATE products
SET `order` = :productOrder,
product_category_id = :productCategoryId,
updated_at = NOW()
WHERE products.id = :productId AND products.event_id = :eventId
", [
"productOrder" => $productOrders[$i],
"productCategoryId" => $productCategoryIds[$i],
"productId" => $productIds[$i],
"eventId" => $eventId,
]);
}
} else {

$productParameters = [
'eventId' => $eventId,
'productIds' => '{' . implode(',', $productIds) . '}',
'productOrders' => '{' . implode(',', $productOrders) . '}',
'productCategoryIds' => '{' . implode(',', $productCategoryIds) . '}',
];

$productUpdateQuery = "WITH new_order AS (
SELECT unnest(:productIds::bigint[]) AS product_id,
unnest(:productOrders::int[]) AS order,
unnest(:productCategoryIds::bigint[]) AS category_id
Expand All @@ -222,18 +240,33 @@ public function bulkUpdateProductsAndCategories(int $eventId, array $productUpda
FROM new_order
WHERE products.id = new_order.product_id AND products.event_id = :eventId";

$this->db->update($productUpdateQuery, $productParameters);
$this->db->update($productUpdateQuery, $productParameters);
}

$categoryIds = array_column($categoryUpdates, 'id');
$categoryOrders = array_column($categoryUpdates, 'order');

$categoryParameters = [
'eventId' => $eventId,
'categoryIds' => '{' . implode(',', $categoryIds) . '}',
'categoryOrders' => '{' . implode(',', $categoryOrders) . '}',
];

$categoryUpdateQuery = "WITH new_category_order AS (
if (DB::getDriverName() === 'mysql') {
for ($i = 0; $i < count($categoryIds); $i++) {
$this->db->update("UPDATE product_categories
SET `order` = :categoryOrder,
updated_at = NOW()
WHERE product_categories.id = :categoryId AND product_categories.event_id = :eventId
", [
"categoryOrder" => $categoryOrders[$i],
"categoryId" => $categoryIds[$i],
"eventId" => $eventId,
]);
}
} else {

$categoryParameters = [
'eventId' => $eventId,
'categoryIds' => '{' . implode(',', $categoryIds) . '}',
'categoryOrders' => '{' . implode(',', $categoryOrders) . '}',
];

$categoryUpdateQuery = "WITH new_category_order AS (
SELECT unnest(:categoryIds::bigint[]) AS category_id,
unnest(:categoryOrders::int[]) AS order
)
Expand All @@ -243,7 +276,8 @@ public function bulkUpdateProductsAndCategories(int $eventId, array $productUpda
FROM new_category_order
WHERE product_categories.id = new_category_order.category_id AND product_categories.event_id = :eventId";

$this->db->update($categoryUpdateQuery, $categoryParameters);
$this->db->update($categoryUpdateQuery, $categoryParameters);
}

$this->db->commit();
} catch (Exception $e) {
Expand Down
5 changes: 3 additions & 2 deletions backend/app/Repository/Eloquent/QuestionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Database\DatabaseManager;
use Illuminate\Foundation\Application;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class QuestionRepository extends BaseRepository implements QuestionRepositoryInterface
{
Expand Down Expand Up @@ -84,14 +85,14 @@ public function sortQuestions(int $eventId, array $orderedQuestionIds): void
'orders' => '{' . implode(',', range(1, count($orderedQuestionIds))) . '}',
];

$query = "WITH new_order AS (
$query = str_replace('"', DB::getDriverName() === 'mysql' ? '`' : "", "WITH new_order AS (
SELECT unnest(:questionIds::bigint[]) AS question_id,
unnest(:orders::int[]) AS order
)
UPDATE questions
SET \"order\" = new_order.order
FROM new_order
WHERE questions.id = new_order.question_id AND questions.event_id = :eventId";
WHERE questions.id = new_order.question_id AND questions.event_id = :eventId");

$this->db->update($query, $parameters);
}
Expand Down
14 changes: 12 additions & 2 deletions backend/app/Services/Domain/Event/EventStatsFetchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use HiEvents\Services\Domain\Event\DTO\EventDailyStatsResponseDTO;
use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

readonly class EventStatsFetchService
{
Expand Down Expand Up @@ -65,8 +66,14 @@ public function getDailyEventStats(EventStatsRequestDTO $requestData): Collectio

$startDate = $requestData->start_date;
$endDate = $requestData->end_date;

$query = <<<SQL
$withStatement = DB::getDriverName() === 'mysql' ? '
WITH RECURSIVE date_series AS (
SELECT CAST(:startDate AS DATE) AS date
UNION ALL
SELECT DATE_ADD(date, INTERVAL 1 DAY)
FROM date_series
WHERE date < CAST(:endDate AS DATE)
)' : "
WITH date_series AS (
SELECT date::date
FROM generate_series(
Expand All @@ -75,6 +82,9 @@ public function getDailyEventStats(EventStatsRequestDTO $requestData): Collectio
'1 day'
) AS gs(date)
)
";
$query = <<<SQL
$withStatement
SELECT
ds.date,
COALESCE(SUM(eds.total_fee), 0) AS total_fees,
Expand Down
Loading
Loading