1

My Laravel app is running on docker using Linux commands on a Windows Machine. This means instead of using 'php artisan' commands, I use 'sail artisan' commands. I am able to migrate locally onto the SQL server on docker (sail artisan migrate) and am able to deploy the app onto Google Cloud (gcloud app deploy). The final bit of my puzzle piece is migrating the database onto the Google Cloud SQL server. When I was first setting the app up, I had problems with this so I exported the SQL server, uploaded it to Google Cloud and then deployed it manually which was fine for a one-off but I now have things I would like to change about the database structure without losing all the data. I also figured it was about time I learnt to do it properly anyway.

I have attempted to use the instructions on Google's community tutorial, however, this guide presupposes the project does not yet exist whereas I am working with a pre-existing application and a pre-existing database. I tried to jump into the tutorial halfway through but I couldn't get the Cloud SQL proxy to work. After a bit more research, I found this article which I got partway through, however, once I got to the part needing TCP or Unix sockets, neither set of commands will run without error on my Ubuntu terminal.

If anyone knows of any useful articles or has had this problem themself, I would greatly appreciate your help.

Additional Info:

  • Laravel Framework 8.69.0
  • Vue version 3.0.5
  • Docker Engine Community 20.10.8
  • SQL server 'europe-west2'
Sam Dean
  • 433
  • 7
  • 22
  • 1
    I've not used Cloud SQL for SQL Server but I suspect the process is SQL Server specific and this may be why you're struggling to find documentation. You will need to provision a Cloud SQL for SQL Server instance and, one you're able to connect to it (this is well-documented), you would perform a migration just like in any other SQL Server deployment. Cloud SQL for SQL Server is just a Google run version of SQL Server and, beyond server management, you interact as you would with any other instance. – DazWilkin Feb 14 '22 at 17:31
  • 1
    See e.g. [Best practices for import and export](https://cloud.google.com/sql/docs/sqlserver/import-export). There's also [backups](https://cloud.google.com/sql/docs/sqlserver/backup-recovery/backups) and restore. I assume there are other SQL Server tools that you can use too. – DazWilkin Feb 14 '22 at 17:32
  • 1
    Have you checked out this documentation about [Migrating data between SQL Server 2017 and Cloud SQL for SQL Server using backup files](https://cloud.google.com/solutions/migrating-data-between-sql-server-2017-and-cloud-sql-for-sql-server-using-backup-files)? – Rogelio Monter Feb 15 '22 at 20:12
  • 1
    Something very useful you could share to investigate this problem (in addition to what the other comments and answers have suggested) is the error message you received when configuring the CloudSQL proxy, in addition to any messages you received from the command sets you ran to configure the TCP/Unix sockets. This, in order to investigate what might be going wrong. – ErnestoC Feb 18 '22 at 22:44

1 Answers1

3

I'm not aware of anyway to run sail/artisan command line commands on GCP.

However in ./vendor/facade/ignition/src/Solutions/RunMigrationsSolution.php there is the following function

public function run(array $parameters = [])
{
    Artisan::call('migrate');
}

which can be used to programmatically run migrations.

So in ./routes/web.php make a route like

Route::get('/run_migrate', 
    [DataController::class, 'runMigrate']
)->middleware(['auth', 'verified'])->name('run_migrate');

and in ./app/Http/Controllers/DataController.php add the function

public function runMigrate() {
    Artisan::call('migrate');
}

Now after signing in as an authorised user (or if you remove the auth middleware you won't need to sign in) you can go to https://your-app-url.com/run_migrate and it will run any outstanding migrations.

To be able to do this the schema table has to exist so you will have to import your local database to start.

Sam Dean
  • 433
  • 7
  • 22