Skip to content

UBE-3: Add DBML cli and makefile to convert sql and dbml files #1

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

Merged
merged 1 commit into from
Apr 4, 2025
Merged
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
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BASE_PATH=./
BUILD_ROOT_PATH=/app/
PROJECT_NAME=laravel_migrations_generator

PHP_BUILD_VERSION=7.4
PHP_TEST_VERSION=8.3
XDEBUG_VERSION=3.3.2
NODE_VERSION=20.2.0

HOST_IP_ADDRESS=host-gateway
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.idea
/build
/docker
/report
/migrations
/storage
Expand All @@ -13,7 +12,10 @@
.phpunit.result.cache
_ide_helper.php
check_migrations.sh
docker-compose.yml
composer.lock
coverage.xml
phpunit.xml
.env
*.log
*.dbml
*.sql
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Defaults
SQL ?= database.sql
DBML ?= database.dbml
RDBMS ?= mysql

# Supported RDBMS options
SUPPORTED_RDBMS := mysql postgres

# Helper function to validate RDBMS
define check_rdbms
@rdbms_valid=0; \
for item in $(SUPPORTED_RDBMS); do \
if [ "$(RDBMS)" = "$$item" ]; then rdbms_valid=1; fi; \
done; \
if [ "$$rdbms_valid" -ne 1 ]; then \
echo "❌ Error: Unsupported RDBMS '$(RDBMS)'. Supported: $(SUPPORTED_RDBMS)"; \
exit 1; \
fi
endef

# Convert SQL to DBML
convertSqlToDbml:
$(call check_rdbms)
@if [ ! -f "$(SQL)" ]; then \
echo "❌ Error: SQL file '$(SQL)' not found."; \
exit 1; \
fi
sql2dbml $(SQL) --$(RDBMS) -o $(DBML)

# Convert DBML to SQL
convertDbmlToSql:
$(call check_rdbms)
@if [ ! -f "$(DBML)" ]; then \
echo "❌ Error: DBML file '$(DBML)' not found."; \
exit 1; \
fi
dbml2sql $(DBML) --$(RDBMS) -o $(SQL)
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
services:

build:
build:
context: ./
dockerfile: docker/Dockerfile
target: build
args:
PHP_BUILD_VERSION: $PHP_BUILD_VERSION
BUILD_ROOT_PATH: $BUILD_ROOT_PATH
PHP_TEST_VERSION: $PHP_TEST_VERSION
XDEBUG_VERSION: $XDEBUG_VERSION
NODE_VERSION: $NODE_VERSION
container_name: "${PROJECT_NAME}_build"
working_dir: ${BUILD_ROOT_PATH}
volumes:
- ${BASE_PATH}:${BUILD_ROOT_PATH}

test:
extra_hosts:
- "host.docker.internal:${HOST_IP_ADDRESS}"
build:
context: ./
dockerfile: docker/Dockerfile
target: test
args:
BUILD_ROOT_PATH: $BUILD_ROOT_PATH
PHP_BUILD_VERSION: $PHP_BUILD_VERSION
PHP_TEST_VERSION: $PHP_TEST_VERSION
XDEBUG_VERSION: $XDEBUG_VERSION
NODE_VERSION: $NODE_VERSION
container_name: "${PROJECT_NAME}_test"
working_dir: ${BUILD_ROOT_PATH}
volumes:
- ${BASE_PATH}:${BUILD_ROOT_PATH}
53 changes: 53 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ARG PHP_BUILD_VERSION
ARG PHP_TEST_VERSION

# Composer on correct PHP version
FROM php:${PHP_BUILD_VERSION}-cli AS build

ARG BUILD_ROOT_PATH
ARG NODE_VERSION

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN apt-get update
RUN apt-get install -y zip unzip curl git
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Node
RUN apt install -y curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install $NODE_VERSION
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

# DBML cli
RUN npm install -g @dbml/cli

WORKDIR ${BUILD_ROOT_PATH}
COPY . ./


FROM php:${PHP_TEST_VERSION}-cli AS test

ARG BUILD_ROOT_PATH
ARG XDEBUG_VERSION

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN pecl install xdebug-${XDEBUG_VERSION}
RUN docker-php-ext-install pcntl
RUN docker-php-ext-install posix

WORKDIR ${BUILD_ROOT_PATH}
COPY --from=build ${BUILD_ROOT_PATH} ${BUILD_ROOT_PATH}


# Install PHP dev dependencies
FROM build AS vendor-dev

ARG BUILD_ROOT_PATH

WORKDIR ${BUILD_ROOT_PATH}
RUN COMPOSER_DISCARD_CHANGES=true composer install