Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2937ad

Browse files
authored
More local-dev work (#1051)
1 parent79cd4fe commite2937ad

File tree

6 files changed

+159
-29
lines changed

6 files changed

+159
-29
lines changed

‎packages/cargo-pgml-components/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎packages/cargo-pgml-components/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name ="cargo-pgml-components"
3-
version ="0.1.18-alpha.1"
3+
version ="0.1.18-alpha.2"
44
edition ="2021"
55
authors = ["PostgresML <team@postgresml.org>"]
66
license ="MIT"

‎packages/cargo-pgml-components/src/local_dev.rs

Lines changed: 141 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
//! Code to handle the setup of our pretty complex local development
44
//! environment.
55
6-
usecrate::util::{execute_command, info, ok_or_error, print, psql_output, unwrap_or_exit, warn};
7-
use std::process::Command;
6+
usecrate::util::{
7+
compare_files, error, execute_command, info, ok_or_error, print, psql_output, unwrap_or_exit,
8+
warn,
9+
};
10+
use std::path::Path;
11+
use std::process::{exit,Command};
812

913
#[cfg(target_os ="macos")]
1014
staticPG_INSTALL:&str ="
@@ -39,7 +43,7 @@ To install pg_stat_statements into your database:
3943
2. Add pg_stat_statements into your shared_preload_libraries:\n
4044
\tpsql -c 'ALTER SYSTEM SET shared_preload_libraries TO pgml,pg_stat_statements'
4145
3. Restart PostgreSQL:\n
42-
\tbrewservice restart postgresql@15
46+
\tbrewservices restart postgresql@15
4347
";
4448

4549
#[cfg(target_os ="linux")]
@@ -55,18 +59,20 @@ To install pg_stat_statements into your database:
5559
";
5660

5761
#[cfg(target_os ="macos")]
58-
staticPG_PGVECTOR:&str ="Install pgvector into your PostgreSQL database:\n
59-
\tgit clone --branch v0.5.0 https://github.com/pgvector/pgvector &&\\
60-
\tcd pgvector &&\\
62+
staticPG_PGVECTOR:&str ="
63+
\t rm -rf /tmp/pgvector &&\\
64+
\tgit clone --branch v0.5.0 https://github.com/pgvector/pgvector /tmp/pgvector &&\\
65+
\tcd /tmp/pgvector &&\\
6166
\techo\"trusted = true\" >> vector.control &&\\
6267
\tmake &&\\
6368
\tmake install
6469
";
6570

6671
#[cfg(target_os ="linux")]
67-
staticPG_PGVECTOR:&str ="Install pgvector into your PostgreSQL database:\n
68-
\tgit clone --branch v0.5.0 https://github.com/pgvector/pgvector &&\\
69-
\tcd pgvector &&\\
72+
staticPG_PGVECTOR:&str ="
73+
\t rm -rf /tmp/pgvector &&\\
74+
\tgit clone --branch v0.5.0 https://github.com/pgvector/pgvector /tmp/pgvector &&\\
75+
\tcd /tmp/pgvector &&\\
7076
\techo\"trusted = true\" >> vector.control &&\\
7177
\tmake &&\\
7278
\tsudo make install
@@ -111,7 +117,7 @@ Is PostgreSQL running and accepting connections?
111117
let start =format!(
112118
"
113119
To start PostgreSQL, run:\n
114-
\tbrewservice start postgresql@15
120+
\tbrewservices start postgresql@15
115121
"
116122
);
117123

@@ -155,18 +161,49 @@ fn dependencies() -> anyhow::Result<()> {
155161
BUILD_ESSENTIAL
156162
);
157163

158-
ok_or_error!(
159-
"checking for PostgreSQL connectivity",
160-
{
161-
ifletErr(err) = psql_output("SELECT version()"){
162-
error!("{}", err);
163-
false
164-
} else{
165-
true
166-
}
167-
},
168-
postgres_running()
169-
);
164+
#[cfg(target_os ="macos")]
165+
{
166+
print("checking for brew...");
167+
ifexecute_command(Command::new("which").arg("brew")).is_err(){
168+
error("missing");
169+
println!("\nBrew is not installed. Install it from https://brew.sh/\n");
170+
exit(1);
171+
}else{
172+
info("ok");
173+
}
174+
}
175+
176+
#[cfg(target_os ="linux")]
177+
let postgres_service ="postgresql";
178+
179+
#[cfg(target_os ="macos")]
180+
let postgres_service ="postgresql@15";
181+
182+
print("checking if PostgreSQL is running...");
183+
if !check_service_running(postgres_service){
184+
error("error");
185+
186+
println!("\nPostgreSQL service is not running. To start PostgreSQL, run:\n");
187+
188+
#[cfg(target_os ="linux")]
189+
println!("\tsudo service postgresql start\n");
190+
191+
#[cfg(target_os ="macos")]
192+
println!("\tbrew services start postgresql@15\n");
193+
194+
exit(1);
195+
}else{
196+
info("ok");
197+
}
198+
199+
print("checking for PostgreSQL connectivity...");
200+
ifletErr(err) =psql_output("SELECT version()"){
201+
error("error");
202+
error!("{}", err);
203+
println!("{}", postgres_running());
204+
}else{
205+
info("ok");
206+
}
170207

171208
ok_or_error!(
172209
"checking for pgvector PostgreSQL extension",
@@ -219,6 +256,7 @@ fn dependencies() -> anyhow::Result<()> {
219256
let output =psql_output(
220257
"SELECT datname FROM pg_database WHERE datname = 'pgml_dashboard_development'",
221258
)?;
259+
222260
if !output.contains("pgml_dashboard_development"){
223261
warn("missing");
224262
print("creating pgml_dashboard_development database...");
@@ -242,6 +280,55 @@ fn dependencies() -> anyhow::Result<()> {
242280
.arg("pgml_dashboard_development")
243281
));
244282
info("ok");
283+
}else{
284+
info("ok");
285+
print("running quick environment test...");
286+
unwrap_or_exit!(execute_command(
287+
Command::new("dropdb")
288+
.arg("--if-exists")
289+
.arg("pgml_components_environment_test")
290+
));
291+
unwrap_or_exit!(execute_command(
292+
Command::new("createdb").arg("pgml_components_environment_test")
293+
));
294+
unwrap_or_exit!(execute_command(
295+
Command::new("psql")
296+
.arg("-c")
297+
.arg("CREATE EXTENSION vector")
298+
.arg("pgml_components_environment_test")
299+
));
300+
unwrap_or_exit!(execute_command(
301+
Command::new("psql")
302+
.arg("-c")
303+
.arg("CREATE EXTENSION pgml")
304+
.arg("pgml_components_environment_test")
305+
));
306+
unwrap_or_exit!(execute_command(
307+
Command::new("dropdb").arg("pgml_components_environment_test")
308+
));
309+
info("ok");
310+
}
311+
312+
print("checking .env file...");
313+
let env =Path::new(".env");
314+
let env_template =Path::new(".env.development");
315+
316+
if !env.exists() && env_template.exists(){
317+
unwrap_or_exit!(execute_command(
318+
Command::new("cp").arg(".env.development").arg(".env")
319+
));
320+
info("ok");
321+
}elseif env.exists() && env_template.exists(){
322+
let identical =unwrap_or_exit!(compare_files(&env,&env_template));
323+
if !identical{
324+
warn("different");
325+
warn(".env has been modified");
326+
}else{
327+
info("ok");
328+
}
329+
}elseif !env_template.exists(){
330+
warn("unknown");
331+
warn(".env.development not found, can't install or validate .env");
245332
}else{
246333
info("ok");
247334
}
@@ -254,3 +341,35 @@ fn dependencies() -> anyhow::Result<()> {
254341
pubfnsetup(){
255342
unwrap_or_exit!(dependencies())
256343
}
344+
345+
pubfninstall_pgvector(){
346+
#[cfg(target_os ="linux")]
347+
{
348+
let check_sudo =execute_command(Command::new("sudo").arg("ls"));
349+
if check_sudo.is_err(){
350+
println!("Installing pgvector requires sudo permissions.");
351+
exit(1);
352+
}
353+
}
354+
355+
print("installing pgvector PostgreSQL extension...");
356+
357+
let result =execute_command(Command::new("bash").arg("-c").arg(PG_PGVECTOR));
358+
359+
ifletOk(_) = result{
360+
info("ok");
361+
}elseifletErr(ref err) = result{
362+
error("error");
363+
error!("{}", err);
364+
}
365+
}
366+
367+
fncheck_service_running(name:&str) ->bool{
368+
#[cfg(target_os ="linux")]
369+
let command =format!("service {} status", name);
370+
371+
#[cfg(target_os ="macos")]
372+
let command =format!("brew services list | grep {} | grep started", name);
373+
374+
execute_command(Command::new("bash").arg("-c").arg(&command)).is_ok()
375+
}

‎packages/cargo-pgml-components/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ enum Commands {
6565
Add(AddCommands),
6666

6767
/// Setup local dev.
68-
LocalDev{},
68+
#[command(subcommand)]
69+
LocalDev(LocalDevCommands),
6970
}
7071

7172
#[derive(Subcommand,Debug)]
@@ -74,6 +75,13 @@ enum AddCommands {
7475
Component{name:String},
7576
}
7677

78+
#[derive(Subcommand,Debug)]
79+
enumLocalDevCommands{
80+
/// Setup local dev.
81+
Check{},
82+
InstallPgvector{},
83+
}
84+
7785
fnmain(){
7886
let config =Config::load();
7987
env_logger::init();
@@ -89,7 +97,10 @@ fn main() {
8997
crate::frontend::components::add(&Path::new(&name), pgml_commands.overwrite)
9098
}
9199
},
92-
Commands::LocalDev{} => local_dev::setup(),
100+
Commands::LocalDev(command) =>match command{
101+
LocalDevCommands::Check{} => local_dev::setup(),
102+
LocalDevCommands::InstallPgvector{} => local_dev::install_pgvector(),
103+
},
93104
}
94105
}
95106
}

‎pgml-dashboard/content/docs/guides/setup/developers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Once there, you can initialize `pgrx` and get going:
7070

7171
####Pgrx command line and environments
7272
```commandline
73-
cargo install cargo-pgrx --version "0.9.8" --locked && \
73+
cargo install cargo-pgrx --version "0.10.0" --locked && \
7474
cargo pgrx init # This will take a few minutes
7575
```
7676

‎pgml-dashboard/content/docs/guides/setup/v2/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ brew bundle
3636
PostgresML is written in Rust, so you'll need to install the latest compiler from[rust-lang.org](https://rust-lang.org). Additionally, we use the Rust PostgreSQL extension framework`pgrx`, which requires some initialization steps:
3737

3838
```bash
39-
cargo install cargo-pgrx --version 0.9.8&& \
39+
cargo install cargo-pgrx --version 0.10.0&& \
4040
cargo pgrx init
4141
```
4242

@@ -293,7 +293,7 @@ We use the `pgrx` Postgres Rust extension framework, which comes with its own in
293293

294294
```bash
295295
cd pgml-extension&& \
296-
cargo install cargo-pgrx --version 0.9.8&& \
296+
cargo install cargo-pgrx --version 0.10.0&& \
297297
cargo pgrx init
298298
```
299299

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp