-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updates PHP version, refactor models, add event emission and ot…
…her adjustments.
- Loading branch information
1 parent
81d3a60
commit 54e6185
Showing
174 changed files
with
2,533 additions
and
1,981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea | ||
|
||
/vendor/ | ||
/report | ||
composer.lock | ||
.phpunit.result.cache | ||
*.lock | ||
.phpunit.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
FROM gustavofreze/php:8.2-fpm | ||
|
||
RUN apk update \ | ||
&& apk add libressl-dev \ | ||
&& pecl install mongodb \ | ||
&& docker-php-ext-enable mongodb \ | ||
&& rm -rf /var/cache/apk/* | ||
LABEL author="Gustavo Freze" \ | ||
maintainer="Gustavo Freze" \ | ||
org.label-schema.name="gustavofreze/cheap-delivery" \ | ||
org.label-schema.vcs-url="https://github.com/gustavofreze/cheap-delivery/blob/main/Dockerfile" \ | ||
org.label-schema.schema-version="1.0" | ||
|
||
ARG FLYWAY_VERSION=10.6.0 | ||
|
||
RUN docker-php-ext-install pdo_mysql | ||
|
||
RUN apk --no-cache add tar curl mysql-client openjdk21-jre \ | ||
&& mkdir -p /opt/flyway \ | ||
&& curl -L "https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}-linux-x64.tar.gz" | tar -xz --strip-components=1 -C /opt/flyway \ | ||
&& rm -f /opt/flyway/jre/bin/java \ | ||
&& ln -s /usr/lib/jvm/java-11-openjdk/jre/bin/java /opt/flyway/jre/bin/java \ | ||
&& ln -s /opt/flyway/flyway /usr/local/bin/flyway \ | ||
&& apk del curl tar | ||
|
||
WORKDIR /var/www/html | ||
|
||
COPY ./db /db | ||
|
||
RUN chmod +x /db/entrypoint.sh | ||
|
||
ENTRYPOINT ["bash", "/db/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/cheap-delivery | ||
IMAGE = gustavofreze/php:8.2 | ||
DOCKER_RUN = docker run -u root --rm -it --net=host -v ${PWD}:/app -w /app ${IMAGE} | ||
DOCKER_EXEC = docker exec -it cheap-delivery | ||
|
||
.PHONY: configure run test test-no-coverage review show-reports clean | ||
FLYWAY = docker run --rm -v ${PWD}/db/mysql/migrations:/flyway/sql --env-file=config/local.env --link cheap-delivery-adm --network=cheap-delivery_default -e FLYWAY_EDITION="community" flyway/flyway:10.6.0 | ||
MIGRATE_DB = ${FLYWAY} -locations=filesystem:/flyway/sql -schemas=cheap_delivery_adm | ||
|
||
.PHONY: configure run test test-no-coverage review show-coverage clean migrate-database clean-database | ||
|
||
configure: | ||
@docker-compose up -d --build | ||
@${DOCKER_EXEC} composer update --optimize-autoloader | ||
|
||
run: | ||
configure-local: | ||
@${DOCKER_RUN} composer update --optimize-autoloader | ||
|
||
test: run review | ||
@${DOCKER_RUN} composer tests | ||
test: | ||
@${DOCKER_RUN} composer run test | ||
|
||
test-no-coverage: | ||
@${DOCKER_RUN} composer run test-no-coverage | ||
|
||
test-unit: | ||
@${DOCKER_RUN} composer run test-unit | ||
|
||
test-no-coverage: run review | ||
@${DOCKER_RUN} composer tests-no-coverage | ||
test-integration: | ||
@${DOCKER_RUN} composer run test-integration | ||
|
||
review: | ||
@${DOCKER_RUN} composer review | ||
|
||
show-reports: | ||
show-coverage: | ||
@sensible-browser report/coverage/coverage-html/index.html | ||
|
||
clean: | ||
@sudo chown -R ${USER}:${USER} ${PWD} | ||
@rm -rf report vendor | ||
@rm -rf report vendor *.phpunit *.lock | ||
|
||
migrate-database: | ||
@${MIGRATE_DB} migrate | ||
|
||
clean-database: | ||
@${MIGRATE_DB} clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Api information | ||
API_NAME='Cheap Delivery' | ||
|
||
# Database | ||
MYSQL_DATABASE_HOST=cheap-delivery-adm | ||
MYSQL_DATABASE_PORT=3306 | ||
MYSQL_DATABASE_NAME=cheap_delivery_adm | ||
MYSQL_DATABASE_USER=root | ||
MYSQL_DATABASE_PASSWORD=root | ||
|
||
# Flyway | ||
FLYWAY_URL=jdbc:mysql://cheap-delivery-adm:3306/cheap_delivery_adm?useUnicode=yes&characterEncoding=UTF-8 | ||
FLYWAY_USER=root | ||
FLYWAY_TABLE=schema_history | ||
FLYWAY_SCHEMAS=cheap_delivery_adm | ||
FLYWAY_EDITION=community | ||
FLYWAY_PASSWORD=root | ||
FLYWAY_LOCATIONS=filesystem:/var/www/html/db/mysql/migrations | ||
FLYWAY_CLEAN_DISABLED=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
wait_for_db() { | ||
attempt=0 | ||
max_attempts=60 | ||
db_ready=false | ||
|
||
while [ $attempt -lt $max_attempts ]; do | ||
if mysqladmin ping -h"$MYSQL_DATABASE_HOST" -u"$MYSQL_DATABASE_USER" -p"$MYSQL_DATABASE_PASSWORD" -P"$MYSQL_DATABASE_PORT" --silent; then | ||
db_ready=true | ||
break | ||
fi | ||
|
||
sleep 1 | ||
((attempt++)) | ||
done | ||
|
||
if ! $db_ready; then | ||
echo "Database is not ready after $max_attempts attempts." | ||
exit 1 | ||
fi | ||
} | ||
|
||
wait_for_db | ||
|
||
flyway migrate | ||
|
||
php-fpm -F |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[client] | ||
user = "root" | ||
password = "root" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
DATABASE_NAME="cheap_delivery_adm" | ||
|
||
CREDENTIALS="/scripts/config/credentials.cnf" | ||
CREATE_DATABASE="CREATE DATABASE IF NOT EXISTS ${DATABASE_NAME};" | ||
|
||
printf "\n\nRunning DDL commands for the database %s ... \n\n" "${DATABASE_NAME}" | ||
|
||
mysql --defaults-extra-file="${CREDENTIALS}" -e "${CREATE_DATABASE}" | ||
|
||
printf "\n\nEnd of execution. \n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE carrier | ||
( | ||
id BINARY(16) NOT NULL COMMENT 'Unique identifier for the carrier.', | ||
name VARCHAR(255) NOT NULL COMMENT 'Name of the carrier.', | ||
cost_modality JSON NOT NULL COMMENT 'JSON representation of types and costs of transportation offered by the carrier.', | ||
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT 'Date and time when the carrier record was inserted.', | ||
PRIMARY KEY (id), | ||
INDEX carrier_idx01 (name), | ||
CONSTRAINT carrier_uk01 | ||
UNIQUE (name) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COLLATE = utf8mb4_0900_ai_ci COMMENT ='Table used to persist carrier records.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE shipment | ||
( | ||
id BINARY(16) NOT NULL COMMENT 'Unique identifier for the shipment.', | ||
cost DECIMAL(15, 2) NOT NULL COMMENT 'Cost of the shipment.', | ||
carrier_name VARCHAR(255) NOT NULL COMMENT 'Name of the carrier providing the shipment service.', | ||
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT 'Date and time when the shipment record was inserted.', | ||
PRIMARY KEY (id) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COLLATE = utf8mb4_0900_ai_ci COMMENT ='Table used to persist shipment records.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE TABLE outbox_event | ||
( | ||
id BINARY(16) PRIMARY KEY NOT NULL COMMENT 'UUID that identifies the event in canonical format (separated by hyphen in the form 8-4-4-4-12).', | ||
aggregate_type VARCHAR(255) NOT NULL COMMENT 'Name of the aggregation root that produced the event in CamelCase format.', | ||
aggregate_id VARCHAR(36) NOT NULL COMMENT 'Textual representation of the aggregation root identifier.', | ||
event_type VARCHAR(255) NOT NULL COMMENT 'Name of the event in CamelCase format.', | ||
revision INT NOT NULL COMMENT 'Positive number indicating the version of the payload produced from the event.', | ||
payload JSON NOT NULL COMMENT 'Event payload as a JSON object.', | ||
occurred_on DATETIME(6) NOT NULL COMMENT 'Moment when the event occurred.', | ||
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT 'Date when the record was inserted.', | ||
INDEX outbox_event_idx01 (aggregate_id), | ||
INDEX outbox_event_idx02 (occurred_on), | ||
INDEX outbox_event_idx03 (created_at) | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8mb4 | ||
COLLATE = utf8mb4_0900_ai_ci COMMENT ='Table used to persist events atomically for eventual publication on the message broker.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO carrier(id, name, cost_modality) VALUES(UUID_TO_BIN(UUID()), 'DHL', '{"modality":"Composite","modalityOne":{"cost":10,"modality":"Fixed"},"modalityTwo":{"cost":0.05,"modality":"Linear"}}'), (UUID_TO_BIN(UUID()), 'FedEx', '{"modality":"Composite","modalityOne":{"cost":4.30,"modality":"Fixed"},"modalityTwo":{"cost":0.12,"modality":"Linear"}}'), (UUID_TO_BIN(UUID()), 'Loggi', '{"modality":"Composite","modalityOne":{"modality":"Partial","costModality":{"modality":"Composite","modalityOne":{"cost":2.10,"modality":"Fixed"},"modalityTwo":{"cost":0.12,"modality":"Linear"}},"costCondition":{"name":"WeightSmallerThan","weight":5.00}},"modalityTwo":{"modality":"Partial","costModality":{"modality":"Composite","modalityOne":{"cost":10.00,"modality":"Fixed"},"modalityTwo":{"cost":0.01,"modality":"Linear"}},"costCondition":{"name":"WeightGreaterThanOrEqual","weight":5.00}}}'); |
Oops, something went wrong.