Some fixes and installation documentation (#46)
* 🐛 Fix migration CreateUsersWorkspacesTable with two errors from SQL constraints 🐛 Fix MySQL transaction on CreateUsersWorkspacesTable migration (MariaDB) 🔧 .gitignore for Clockwork * 🚧 Doc Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
parent
6d96a09bd0
commit
9f1f968430
40
README.md
40
README.md
|
@ -35,7 +35,45 @@ It takes 1 minute to try out the builder for free. You'll have high availability
|
||||||
|
|
||||||
## Self-hosting
|
## Self-hosting
|
||||||
|
|
||||||
This section hasn't been written yet, we need to work on this.
|
🚧 This section is under construction!
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
- PHP >= 8.0
|
||||||
|
- MySQL/MariaDB or PostgreSQL
|
||||||
|
- Node.js and NPM/Yarn/... to compile assets
|
||||||
|
|
||||||
|
### Local installation
|
||||||
|
|
||||||
|
First, let's work with the codebase and its dependencies.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Get the code!
|
||||||
|
git clone git@github.com:JhumanJ/OpnForm.git && cd OpnForm
|
||||||
|
|
||||||
|
# Install PHP and JS dependencies
|
||||||
|
composer install && npm install
|
||||||
|
|
||||||
|
# Compile assets (see the scripts section in package.json)
|
||||||
|
npm run dev # or prod, or watch
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, we can configure Laravel. We just need to prepare some vars in our `.env` file, just create it with `cp .env.example .env` then open it!
|
||||||
|
|
||||||
|
Configure the desired database in the `DATABASE_` section. You can fine tune your installation on the [laravel documentation](https://laravel.com/docs/9.x).
|
||||||
|
|
||||||
|
Finally, just run these artisan commands and you're done!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate needed secrets 🙈
|
||||||
|
php artisan key:generate
|
||||||
|
php artisan jwt:secret # and select yes!
|
||||||
|
|
||||||
|
# Creates DB schemas
|
||||||
|
php artisan migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
🎉 Done! Enjoy your personal OpnForm instance at: [http://opnform.test](http://opnform.test).
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class CreateUsersWorkspacesTable extends Migration
|
class CreateUsersWorkspacesTable extends Migration
|
||||||
|
@ -13,38 +14,30 @@ class CreateUsersWorkspacesTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
\Illuminate\Support\Facades\DB::transaction(function () {
|
|
||||||
|
|
||||||
Schema::create('user_workspace', function (Blueprint $table) {
|
Schema::create('user_workspace', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->integer('workspace_id')->unsigned();
|
$table->foreignId('workspace_id')->references('id')->on('workspaces')->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
$table->integer('user_id')->unsigned();
|
$table->foreignId('user_id')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
$table->unique(['workspace_id', 'user_id']);
|
$table->unique(['workspace_id', 'user_id']);
|
||||||
$table->boolean('is_owner')->default(false);
|
$table->boolean('is_owner')->default(false);
|
||||||
$table->string('access_token')->nullable();
|
$table->string('access_token')->nullable();
|
||||||
$table->foreign('workspace_id')->references('id')->on('workspaces')
|
|
||||||
->onDelete('cascade')->onUpdate('cascade');
|
|
||||||
$table->foreign('user_id')->references('id')->on('users')
|
|
||||||
->onDelete('cascade')->onUpdate('cascade');
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add creator id to forms table
|
// Add creator id to forms table
|
||||||
Schema::table('forms', function (Blueprint $table) {
|
Schema::table('forms', function (Blueprint $table) {
|
||||||
$table->integer('creator_id')->unsigned()->nullable();
|
$table->foreignId('creator_id')->references('id')->on('users')->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
$table->foreign('creator_id')->references('id')->on('users')
|
|
||||||
->onDelete('cascade')->onUpdate('cascade');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create relation - can't use models because of new methods clash
|
// Create relation - can't use models because of new methods clash
|
||||||
\Illuminate\Support\Facades\DB::table('workspaces')
|
DB::table('workspaces')
|
||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->chunk(100, function ($workspaces) {
|
->chunk(100, function ($workspaces) {
|
||||||
foreach ($workspaces as $workspace) {
|
foreach ($workspaces as $workspace) {
|
||||||
echo '.';
|
echo '.';
|
||||||
|
|
||||||
// Make sure user wasn't deleted
|
// Make sure user wasn't deleted
|
||||||
if (!\Illuminate\Support\Facades\DB::table('users')->where('id',
|
if (!DB::table('users')->where('id',
|
||||||
$workspace->user_id)->exists()) {
|
$workspace->user_id)->exists()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +68,6 @@ class CreateUsersWorkspacesTable extends Migration
|
||||||
Schema::table('user_workspace', function (Blueprint $table) {
|
Schema::table('user_workspace', function (Blueprint $table) {
|
||||||
$table->string('access_token')->nullable(false)->change();
|
$table->string('access_token')->nullable(false)->change();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
*.json
|
||||||
|
*.json.gz
|
||||||
|
index
|
Loading…
Reference in New Issue