Skip to content

Commit

Permalink
Merge pull request #250 from yahu1031/windows_table_setup
Browse files Browse the repository at this point in the history
feat: Windows table setup
  • Loading branch information
vlidholt committed Sep 7, 2022
2 parents 620e0b9 + 38578cf commit 255abcc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
22 changes: 22 additions & 0 deletions templates/serverpod_templates/projectname_server/setup-tables.cmd
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions tools/serverpod_cli/bin/create/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Future<void> performCreate(
'Unknown template: $template (valid options are "server" or "module")');
}

if (dockerConfigured && !Platform.isWindows) {
if (dockerConfigured) {
await CommandLineTools.createTables(projectDir, name);

printwwln('');
Expand All @@ -362,11 +362,6 @@ Future<void> 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');
Expand Down
24 changes: 16 additions & 8 deletions tools/serverpod_cli/bin/util/command_line_tools.dart
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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,
);
Expand Down

0 comments on commit 255abcc

Please sign in to comment.