diff --git a/templates/serverpod_templates/projectname_server/setup-tables.cmd b/templates/serverpod_templates/projectname_server/setup-tables.cmd new file mode 100644 index 0000000000..8851e86d58 --- /dev/null +++ b/templates/serverpod_templates/projectname_server/setup-tables.cmd @@ -0,0 +1,22 @@ +@echo off + +@REM Start docker +echo Starting docker +docker-compose up --build --detach + +:LOOP +netstat -o -n -a | >nul findstr "8090" && ( + echo Waiting for Postgres... + sleep 2 + goto :PORT_FOUND +) +echo Waiting for Postgres... +goto :LOOP + +:PORT_FOUND +echo Postgres is ready +cat .\generated\tables-serverpod.pgsql | docker-compose run -T postgres env PGPASSWORD="DB_PASSWORD" psql -h postgres -U postgres -d projectname +echo Stopping docker +docker-compose stop + +exit /b diff --git a/tools/serverpod_cli/bin/create/create.dart b/tools/serverpod_cli/bin/create/create.dart index edc443e610..f84e9e786e 100644 --- a/tools/serverpod_cli/bin/create/create.dart +++ b/tools/serverpod_cli/bin/create/create.dart @@ -336,7 +336,7 @@ Future performCreate( 'Unknown template: $template (valid options are "server" or "module")'); } - if (dockerConfigured && !Platform.isWindows) { + if (dockerConfigured) { await CommandLineTools.createTables(projectDir, name); printwwln(''); @@ -362,11 +362,6 @@ Future performCreate( stdout.writeln(' \$ cd ${p.join(name, '${name}_server')}'); stdout.writeln(' \$ docker-compose up --build --detach'); printww(''); - printwwln( - 'When your docker container is up and running you need to install the default Serverpod postgres tables. (You only need to to this once.)'); - stdout.writeln( - ' \$ Get-Content .\\generated\\tables-serverpod.pgsql | docker-compose run -T postgres env PGPASSWORD="$dbPassword" psql -h postgres -U postgres -d $name'); - printww(''); printwwln( 'Unfortunately `serverpod run` is not yet supported on Windows, but you should be able to start Serverpod by running:'); stdout.writeln(' \$ dart .\\bin\\main.dart'); diff --git a/tools/serverpod_cli/bin/util/command_line_tools.dart b/tools/serverpod_cli/bin/util/command_line_tools.dart index fe360ba46c..cda35dcfe9 100644 --- a/tools/serverpod_cli/bin/util/command_line_tools.dart +++ b/tools/serverpod_cli/bin/util/command_line_tools.dart @@ -1,9 +1,10 @@ import 'dart:async'; import 'dart:io'; +import 'package:path/path.dart' as p; + import 'print.dart'; import 'windows.dart'; -import 'package:path/path.dart' as p; class CommandLineTools { static void dartPubGet(Directory dir) { @@ -48,15 +49,22 @@ class CommandLineTools { printww('Setting up Docker and default database tables in $serverPath'); printww( 'If you run serverpod create for the first time, this can take a few minutes as Docker is downloading the images for Postgres. If you get stuck at this step, make sure that you have the latest version of Docker Desktop and that it is currently running.'); - var result = await Process.run( - 'chmod', - ['u+x', 'setup-tables'], - workingDirectory: serverPath, - ); - print(result.stdout); + late ProcessResult result; + if (!Platform.isWindows) { + result = await Process.run( + 'chmod', + ['u+x', 'setup-tables'], + workingDirectory: serverPath, + ); + print(result.stdout); + } var process = await Process.start( - './setup-tables', + /// Windows has an issue with running batch file directly without the complete path. + /// Related ticket: https://github.com/dart-lang/sdk/issues/31291 + Platform.isWindows + ? p.join(serverPath, 'setup-tables.cmd') + : './setup-tables', [], workingDirectory: serverPath, );