Extend Laravel PHP framework to make working with Aiven databases simpler

Overview

Aiven Commands for Laravel

Add some Aiven magic to your Laravel project

This Laravel package provides some aiven commands for artisan to help with managing your development databases and producing the correct configuration to use with them. This version supports both MySQL and PostgreSQL.

Use the commands to:

  • List the Aiven services in your project
  • Power your databases on and off from artisan, so you don't leave the meter running when you're not working
  • Get database config you can paste straight into your .env file or environment.

Getting started

Install the package with Composer:

composer require aiven/aiven-laravel

You will need an Aiven account - sign up for a free trial if you don't have one already. Go ahead and create the database(s) you'll be using in your project through the web interface, or investigate the Aiven CLI.

Get an auth token for your Aiven account, and set it as AIVEN_API_TOKEN in your environment.

It's recommended to also set AIVEN_DEFAULT_PROJECT as the project in your Aiven account that you'll be using services from (but you can also supply --project [projectname] for all the commands instead if you like)

Usage

Get a list of the Aiven services (databases) available:

php artisan aiven:list 

Get the environment variables to export or paste into .env for a particular service:

php artisan aiven:getconfig --service my-postgres-db

When you use the DATABASE_URL in Laravel, you must remove the existing DB_HOST, DB_PORT, etc configuration so that it does not conflict.

Check the status of the service:

php artisan aiven:state --service my-postgres-db

Power the service on or off:

php artisan aiven:powerup --service my-postgres-db
php artisan aiven:powerdown --service my-postgres-db

It's useful to power things down when you're not using them so that you aren't being charged (even if you're still paying in trial credits!)

Datastore-specific setup

MySQL and PostgreSQL

PHP is on good terms with relational databases, and Laravel makes this very straight forward.

  1. Remove all the configuration entries from .env starting with DB_

  2. Paste the output of the aiven:getconfig command. For both MySQL and PostgreSQL, this is a DATABASE_URL. For PostgreSQL, we need to tell Laravel we want to use Postgres (MySQL is the default) so the command also outputs DB_CONNECTION=pgsql and this should also be included.

Redis

Redis needs some extra dependencies (see Laravel Redis docs), and then you can set the REDIS_URL to the value returned by aiven:getconfig.

OpenSearch with Laravel Scout

This uses some Elasticsearch libraries because the OpenSearch project is a fork so they are reasonably compatible.

  • Use Laravel Scout

  • Add Explorer

  • Pin your PHP elasticsearch library dependencies, I have this in composer.json:

=7.9 <7.14", ">
        "elasticsearch/elasticsearch": ">=7.9 <7.14",

The aiven:getconfig command will give you just the connection string for an OpenSearch service; put this in the config/explorer.php so that it looks something like this:

    'connection' => "https://avnadmin:[email protected]:port",

The Scout documentation has a good overview of how to make your models searchable, and the Explorer project adds commands to create the index.

Troubleshooting

MySQL primary key errors

Laravel's initial migrations assumes that your MySQL database doesn't enforce primary keys (see related bug for more info) - disable the mysql.sql_require_primary_key setting on Aiven if you run into this.

Connection problems

If you add the config to your environment and still can't connect, check that you don't have other environment variables with names starting DB_ ... values like DB_HOST should be removed when you use the DATABASE_URL field to connect.

Get in touch

Questions? Problems? Open an issue and let us know.

You might also like...
Make Laravel Pivot Tables using the new Laravel 9 closure migration format

This will allow you to create pivot table migration files using the new Laravel 9 closure migration format by simply passing two models.

Make your Laravel app comply with the crazy EU cookie law
Make your Laravel app comply with the crazy EU cookie law

Make your Laravel app comply with the crazy EU cookie law All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy EU l

A package to easily make use of Iconic icons in your Laravel Blade views.
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

A package to easily make use of Simple Icons in your Laravel Blade views.
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

Make your Laravel app comply with the refuse/accept cookie law

Make your Laravel app comply with the refuse/accept cookie law All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy

A simple `make:view` command for Laravel applications.

A simple make:view command for Laravel applications. Quickly generate a new Blade view from the console using artisan make:view. Installation You can

This package gives you a set of conventions to make the most out of Hotwire in Laravel

Introduction This package gives you a set of conventions to make the most out of Hotwire in Laravel (inspired by the turbo-rails gem). There is a comp

Make any class queue aware in a Laravel app
Make any class queue aware in a Laravel app

Make any class queue aware This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support us We in

Interactive Make Command for Laravel
Interactive Make Command for Laravel

Interactive Make for Laravel 5.4 Getting Started To get started you need to install the package with Composer: composer require laracademy/interactive

Comments
  • Constants

    Constants

    Adds inferred requires from the code and changes magic numbers for constants. With constants such as $this::FAILURE; the comments indicating failure could be removed.

    opened by ordago 0
Releases(v1.0.0)
  • v1.0.0(Oct 6, 2021)

    First integration with Aiven: list services and make config-file-ready configuration to paste for MySQL, PostgreSQL, Redis and OpenSearch.

    Source code(tar.gz)
    Source code(zip)
Owner
Aiven
Aiven
This is huaweinvr extend for laravel

This is huaweinvr extend for laravel

Verus 1 Nov 18, 2021
Extend Kirby’s templates with a powerful layout system

Kirby Layouts plugin This plugin extends Kirby’s templates with a powerful layout system. Installation Download Download and copy this repository to /

Kirby 3 39 Dec 28, 2022
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

karam mustafa 9 Jul 26, 2022
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Watch your Laravel app for unwanted changes when working with third-party packages.

Project Secure This package installs a Composer plugin that reports unwanted changes to your Laravel project code after installing or updating a third

The Laravel Hacker 3 Nov 3, 2021
Helper class for working with Laravel Mix in WordPress themes and plugins.

Hybrid\Mix Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json

Theme Hybrid 9 Jun 2, 2022
Makes working with DateTime fields in Laravel's Nova easier

This package adds a DateTime field with support for a global DateTime format, syntactic sugar for formatting individual DateTime fields and powerful d

wdelfuego 6 Aug 4, 2022
A collection of useful traits for working with PHP 8.1 Enums

A library of helper traits for working with PHP 8.1 enums This package provides a series of traits that allows you to: RestorableFromName Trait Create

Mark Baker 24 Nov 24, 2022
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model->myPoint = new Point(1,2); //lat

Max 340 Jan 6, 2023