dev-resources.site
for different kinds of informations.
Integrate Daytonia in a Url Shortener App
What is Daytona?
Daytona is a powerful open-source tool that makes development environment management effortless. With just one command, developers can instantly spin up standardized environments that work seamlessly with popular IDEs, including VS Code, Cursors, Jupyter, and the full JetBrains suite. Our free offering includes comprehensive SDK, giving developers and AI agents programmatic control over environment creation, Git operations, and workspace configurations.
How I Integrated Daytona in a URL Shortener App
**Daytonia **is a managed database platform that allows you to deploy and manage databases effortlessly. I used Daytonia to host the MySQL database for the URL Shortener application. Here's how I integrated Daytonia into this project:
Steps to Integrate Datonia with the URL Shortener App
Set Up a MySQL Database on Daytonia
- Visit the Datonia GitHub Repository or go directly to their website.
- Create an account on Datonia (or log in if you already have one).
- Deploy a new MySQL database instance:
- Specify your database name, username, and password.
- Copy the connection details (e.g., host, port, username, password, database name).
Update Environment Variables
In the URL Shortener project, locate the .env file.
Update the database connection settings with the details provided by Datonia:
For example:
DB_HOST=mysql.datonia.io
DB_PORT=3306
DB_DATABASE=url_shortener
DB_USERNAME=admin
DB_PASSWORD=supersecurepassword
Update Docker Compose File (If Using Docker)
If you're using Docker to run the app (as I did), ensure that your docker-compose.yml file is configured to use the external Datonia database. Replace the default mysql service configuration with the external Datonia details.
For example:
services:
app:
build:
context: .
ports:
- "8080:80"
env_file:
- .env
Since Datonia is managing the MySQL database, I no longer need the mysql
service in my docker-compose.yml
file.
Import Database Schema into Datonia
- Export the existing database schema or use the url_shortener.sql file provided in the project.
- Import the schema into your Datonia-managed MySQL instance:
- Use a MySQL client like MySQL Workbench or a CLI tool.
- Example command to import the schema:
mysql -h <datonia-mysql-host> -u <username> -p <database-name> < database/url_shortener.sql
Test the Application
- Start the application using Docker or a local server.
- The app should now connect to the Daytonia-managed MySQL database.
- Verify the functionality:
- Create short URLs.
- Ensure the data is being saved and retrieved correctly.
Featured ones: