55 python scripts/quickstart.py [--backend lm_studio|ollama|google] [--model MODEL_NAME]
66 python scripts/quickstart.py --skip-install # Skip pip install, use current env
77"""
8+
89from __future__ import annotations
910
1011import argparse
1112import os
1213import subprocess
1314import sys
15+ import urllib .error
1416import urllib .request
1517from pathlib import Path
1618
@@ -27,18 +29,18 @@ def run(cmd: list[str], check: bool = True) -> subprocess.CompletedProcess[str]:
2729def check_lm_studio () -> bool :
2830 """Check if LM Studio is running."""
2931 try :
30- r = urllib .request .urlopen ("http://127.0.0.1:1234/v1/models" , timeout = 3 )
31- return r .status == 200
32- except Exception :
32+ with urllib .request .urlopen ("http://127.0.0.1:1234/v1/models" , timeout = 3 ) as r :
33+ return r .status == 200
34+ except ( urllib . error . URLError , OSError ) :
3335 return False
3436
3537
3638def check_ollama () -> bool :
3739 """Check if Ollama is running."""
3840 try :
39- r = urllib .request .urlopen ("http://localhost:11434/api/tags" , timeout = 3 )
40- return r .status == 200
41- except Exception :
41+ with urllib .request .urlopen ("http://localhost:11434/api/tags" , timeout = 3 ) as r :
42+ return r .status == 200
43+ except ( urllib . error . URLError , OSError ) :
4244 return False
4345
4446
@@ -47,6 +49,53 @@ def sqlseed_cmd(python: str) -> list[str]:
4749 return [python , "-c" , "from sqlseed.cli.main import cli; cli()" , "--" ]
4850
4951
52+ def _fill_data (python : str ) -> None :
53+ """Fill the demo database with sample data using sqlseed CLI."""
54+ cmd = sqlseed_cmd (python )
55+ for table , count in [("users" , 500 ), ("projects" , 200 ), ("orders" , 1000 )]:
56+ run ([* cmd , "fill" , str (DB_PATH ), "-t" , table , "-n" , str (count )])
57+
58+ print ()
59+ print (" Data fill complete!" )
60+
61+
62+ def _run_ai_analysis_step (args : argparse .Namespace , python : str ) -> None :
63+ """Run the Gemma 4 AI schema analysis step."""
64+ print ("[5/5] Gemma 4 AI Schema Analysis..." )
65+ print (f" Backend: { args .backend } " )
66+ print (f" Model: { args .model } " )
67+ print ()
68+
69+ os .environ ["SQLSEED_AI_BACKEND" ] = args .backend
70+ os .environ ["SQLSEED_AI_MODEL" ] = args .model
71+
72+ ai_ok = False
73+ if args .backend == "lm_studio" :
74+ if check_lm_studio ():
75+ ai_ok = True
76+ else :
77+ print (" Skipped: LM Studio is not running" )
78+ print (" Please start LM Studio and load a Gemma 4 model" )
79+ print (" Download: https://lmstudio.ai/" )
80+ elif args .backend == "ollama" :
81+ if check_ollama ():
82+ ai_ok = True
83+ else :
84+ print (" Skipped: Ollama is not running" )
85+ print (" Example: ollama pull gemma4:4b" )
86+ elif args .backend == "google" :
87+ if os .environ .get ("GOOGLE_API_KEY" ):
88+ ai_ok = True
89+ else :
90+ print (" Skipped: GOOGLE_API_KEY not set" )
91+ print (" Example: export GOOGLE_API_KEY=your-key" )
92+
93+ if ai_ok :
94+ output_yaml = str (PROJECT_ROOT / "projects_config.yaml" )
95+ cmd = sqlseed_cmd (python )
96+ run ([* cmd , "ai-suggest" , str (DB_PATH ), "-t" , "projects" , "-o" , output_yaml , "--timeout" , "300" ])
97+
98+
5099def main () -> None :
51100 parser = argparse .ArgumentParser (description = "GemmaSQLSeed one-click setup" )
52101 parser .add_argument (
@@ -107,48 +156,10 @@ def main() -> None:
107156
108157 # ── Step 4: Fill data ────────────────────────────────────────────
109158 print ("[4/5] Filling data (zero-config)..." )
110-
111- cmd = sqlseed_cmd (python )
112- for table , count in [("users" , 500 ), ("projects" , 200 ), ("orders" , 1000 )]:
113- run (cmd + ["fill" , str (DB_PATH ), "-t" , table , "-n" , str (count )])
114-
115- print ()
116- print (" Data fill complete!" )
159+ _fill_data (python )
117160
118161 # ── Step 5: Gemma 4 AI analysis ──────────────────────────────────
119- print ("[5/5] Gemma 4 AI Schema Analysis..." )
120- print (f" Backend: { args .backend } " )
121- print (f" Model: { args .model } " )
122- print ()
123-
124- os .environ ["SQLSEED_AI_BACKEND" ] = args .backend
125- os .environ ["SQLSEED_AI_MODEL" ] = args .model
126-
127- ai_ok = False
128- if args .backend == "lm_studio" :
129- if check_lm_studio ():
130- ai_ok = True
131- else :
132- print (" Skipped: LM Studio is not running" )
133- print (" Please start LM Studio and load a Gemma 4 model" )
134- print (" Download: https://lmstudio.ai/" )
135- elif args .backend == "ollama" :
136- if check_ollama ():
137- ai_ok = True
138- else :
139- print (" Skipped: Ollama is not running" )
140- print (" Example: ollama pull gemma4:4b" )
141- elif args .backend == "google" :
142- if os .environ .get ("GOOGLE_API_KEY" ):
143- ai_ok = True
144- else :
145- print (" Skipped: GOOGLE_API_KEY not set" )
146- print (" Example: export GOOGLE_API_KEY=your-key" )
147-
148- if ai_ok :
149- output_yaml = str (PROJECT_ROOT / "projects_config.yaml" )
150- cmd = sqlseed_cmd (python )
151- run (cmd + ["ai-suggest" , str (DB_PATH ), "-t" , "projects" , "-o" , output_yaml , "--timeout" , "300" ])
162+ _run_ai_analysis_step (args , python )
152163
153164 # ── Done ─────────────────────────────────────────────────────────
154165 print ()
@@ -157,10 +168,11 @@ def main() -> None:
157168 print ("=" * 50 )
158169 print ()
159170 print (f" Database: { DB_PATH } " )
160- print (f" Preview: python -c \" from sqlseed.cli.main import cli; cli()\" -- preview { DB_PATH } -t users -n 5" )
161- print (f" Inspect: python -c \" from sqlseed.cli.main import cli; cli()\" -- inspect { DB_PATH } --show-mapping" )
162- print (f" AI Suggest: python -c \" from sqlseed.cli.main import cli; cli()\" -- ai-suggest { DB_PATH } -t users -o config.yaml" )
163- print (f" MCP Server: mcp-server-sqlseed" )
171+ cli_call = 'python -c "from sqlseed.cli.main import cli; cli()" --'
172+ print (f" Preview: { cli_call } preview { DB_PATH } -t users -n 5" )
173+ print (f" Inspect: { cli_call } inspect { DB_PATH } --show-mapping" )
174+ print (f" AI Suggest: { cli_call } ai-suggest { DB_PATH } -t users -o config.yaml" )
175+ print (" MCP Server: mcp-server-sqlseed" )
164176 print ()
165177
166178
0 commit comments