Skip to content
Snippets Groups Projects
Commit 1e811c46 authored by MORIN Edouard's avatar MORIN Edouard
Browse files

Passage en version 0.0.0.9010

Introduction lifecycle, correction pour snapshot commentaires. Correction doc. Resolution #31.
parent fc3ad40f
No related branches found
No related tags found
1 merge request!12Mise en place test + #31
Pipeline #529098 passed with warnings
Package: datalibaba
Title: Interface De Connexion a Une Base Posgres Postgis
Version: 0.0.0.9009
Version: 0.0.0.9010
Authors@R:
c(person(given = "Maël",
family = "Theulière",
......@@ -33,11 +33,14 @@ Imports:
magrittr,
tibble,
units,
tidyr
tidyr,
lifecycle
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
backports,
lubridate
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
......
......@@ -25,6 +25,7 @@ export(poster_data)
export(set_schema_rights)
export(standard_var_pg)
export(transferer_table_comments)
import(lifecycle)
importFrom(DBI,Id)
importFrom(DBI,dbConnect)
importFrom(DBI,dbDisconnect)
......
# datalibaba (development version)
# datalibaba 0.0.0.9009
- Gestion des tables non géo dans la fonction `importer_data` : Ajout d'une ligne pour définir explicitement `query_sql_limit` dans la fonction importer_data (cas d'une table non géo).
......
......@@ -91,8 +91,8 @@ importer_data <- function(table = NULL, schema = NULL, db = "public", server =
if ("id_row__" %in% champs$column_name) {
data <- dplyr::arrange(.data = data, .data$id_row__) %>%
dplyr::select(-.data$id_row__)
data <- data %>% dplyr::arrange(id_row__) %>%
dplyr::select(-id_row__)
}
}
......
......@@ -274,18 +274,26 @@ post_data <- function(con,
#' Chargement d'un dataset sur le serveur en dbi
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' Cette fonction a été dépréciée car non fonctionnelle en l'état
#' Elle désormais équivalente à post_data et il est conseillé d'utiliser
#' poster_data
#'
#' @param con Le connecteur de classe PosgreSQLConnection.
#' @param data Un dataframe a importer.
#' @param schema Le nom du schema sur le serveur de donnees.
#' @param table Le nom de la table sur le serveur de donnees.
#' @param overwrite TRUE si on veut ecraser le fichier deja present.
#' @import lifecycle
#' @importFrom attempt stop_if stop_if_not
#' @importFrom DBI dbWriteTable Id
#' @importFrom glue glue
#'
#' @return NULL, la fonction lance le chargement du dataset present dans l'environnement R et son ecriture sur le serveur
#' @export
#' @keywords internal
#'
post_data_dbi <- function(con = NULL,
......@@ -293,7 +301,7 @@ post_data_dbi <- function(con = NULL,
schema = NULL,
table = NULL,
overwrite = FALSE) {
.Deprecated("poster_data")
lifecycle::deprecate_warn("0.0.0.9010", "post_data_dbi()", "poster_data()")
post_data(con=con, data = data, schema = schema, table = table, overwrite = overwrite)
}
......@@ -17,7 +17,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->
mise_en_place_test: [![pipeline status](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/mise_en_place_test/pipeline.svg)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/mise_en_place_test)[![coverage report](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/mise_en_place_test/coverage.svg?job=coverage)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/mise_en_place_test)
[![pipeline status](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/master/pipeline.svg)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)[![coverage report](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/master/coverage.svg?job=coverage)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)
<!-- badges: end -->
{datalibaba} est un ensemble de fonctions visant à faciliter l'alimentation du serveur de données du DREAL <datalab/> Pays de la Loire.
......
......@@ -5,9 +5,9 @@
<!-- badges: start -->
mise_en_place_test: [![pipeline
status](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/mise_en_place_test/pipeline.svg)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/mise_en_place_test)[![coverage
report](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/mise_en_place_test/coverage.svg?job=coverage)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/mise_en_place_test)
[![pipeline
status](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/master/pipeline.svg)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)[![coverage
report](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/badges/master/coverage.svg?job=coverage)](https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/datalibaba/-/commits/master)
<!-- badges: end -->
{datalibaba} est un ensemble de fonctions visant à faciliter
......
Version: 1.0
ProjectId: 643276e3-9018-4b1c-85b4-c14054b6bc51
RestoreWorkspace: No
SaveWorkspace: No
......
......@@ -3,12 +3,15 @@ install.packages("odbc")
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
con <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") != TRUE){
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba") == TRUE){
DBI::dbExecute(con, "DROP DATABASE IF EXISTS test_datalibaba;")
}
DBI::dbExecute(con, "CREATE DATABASE test_datalibaba WITH OWNER = runner ENCODING = 'UTF8' CONNECTION LIMIT = -1;")
dbDisconnect(con)
con <- DBI::dbConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="test_datalibaba")
DBI::dbExecute(con, "CREATE EXTENSION postgis;")
DBI::dbExecute(con, "CREATE EXTENSION postgis_topology;")
}
#autre dbExecute si besoin de plus
#si on veut lire un script sql mesreq.sql, le mettre dans /dev et executer
# system(paste0("( echo dev/mesreq.sql ) | psql \"postgresql://runner:",Sys.getenv("BDD_RUNNER_PWD"),"@127.0.0.1:5432/test_datalibaba\""))
......
......@@ -27,5 +27,10 @@ post_data_dbi(
NULL, la fonction lance le chargement du dataset present dans l'environnement R et son ecriture sur le serveur
}
\description{
Chargement d'un dataset sur le serveur en dbi
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Cette fonction a été dépréciée car non fonctionnelle en l'état
Elle désormais équivalente à post_data et il est conseillé d'utiliser
poster_data
}
\keyword{internal}
# importer_data works
# importer_data no geo works
Code
importer_data(table = "test_iris", schema = "public", db = "test_datalibaba",
......@@ -15,14 +15,10 @@
3 2025-02-27 14:29:32
4 2025-02-27 14:29:32
---
# importer_data geo works
Code
importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test")
Condition
Warning:
Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0.
i Please use `"id_row__"` instead of `.data$id_row__`
Output
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
......@@ -58,10 +54,6 @@
Code
importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test",
limit = 4)
Condition
Warning:
Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0.
i Please use `"id_row__"` instead of `.data$id_row__`
Output
Simple feature collection with 4 features and 14 fields
Geometry type: MULTIPOLYGON
......
# get_table_comment works
Code
get_table_comment(table = "test_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table
1 public test_iris
commentaire
1 la table de test complete\nCommentaire posté le 27/02/2025, par edouard.morin.
# get_cols_comment works
Code
......@@ -21,16 +10,23 @@
# get_table_comments works
Code
get_table_comments(table = "test_iris", schema = "public", db = "test_datalibaba",
get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table commentaire nom_col
1 public retest_iris <NA> <NA>
2 public retest_iris libellé de Sepal.Length cc Sepal.Length
3 public retest_iris libellé de Sepal.Width cc Sepal.Width
4 public retest_iris libellé de Petal.Length cc Petal.Length
5 public retest_iris libellé de Petal.Width cc Petal.Width
6 public retest_iris libellé de Species cc Species
# get_table_comment works
Code
get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba",
user = "test", server = Sys.getenv("server"))
Output
nom_schema nom_table
1 public test_iris
2 public test_iris
commentaire
1 la table de test complete\nCommentaire posté le 27/02/2025, par edouard.morin.
2 Commentlibaba !
nom_col
1 <NA>
2 species
nom_schema nom_table commentaire
1 public retest_iris <NA>
......@@ -6,8 +6,9 @@ library(dplyr)
library(sf)
library(glue)
library(backports)
library(withr)
test_that("importer_data works", {
test_that("importer_data no geo works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
......@@ -40,6 +41,22 @@ test_that("importer_data works", {
"La table de propri\u00e9t\u00e9s des dataframes R est introuvable, un import standard sera r\u00e9alis\u00e9. ")
# test basic
expect_snapshot(importer_data(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", limit = 4, ecoSQL = FALSE))
}else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
print('warning: connect_to_db - local database postgresql doesnt work !')
expect_equal(1,1)
}
})
test_that("importer_data geo works", {
withr::local_options(lifecycle_verbosity = "quiet")
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
# test geometry # pas pris en compte dans le coverage... pourquoi ??
expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test"))
expect_snapshot(importer_data(table = "nc", schema = "public", db = "test_datalibaba", user = "test", limit = 4))
......
......@@ -66,22 +66,21 @@ test_that("post_dico_attr works", {
}
})
test_that("get_table_comment works", {
test_that("get_cols_comment works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
expect_error(get_table_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
expect_error(get_cols_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
expect_error(get_cols_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
expect_error(get_cols_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_snapshot(get_table_comment(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
expect_snapshot(get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
......@@ -90,21 +89,14 @@ test_that("get_table_comment works", {
}
})
test_that("get_cols_comment works", {
test_that("get_table_comments works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
expect_error(get_cols_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_cols_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(get_cols_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_snapshot(get_cols_comment(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
expect_snapshot(get_table_comments(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
......@@ -113,14 +105,22 @@ test_that("get_cols_comment works", {
}
})
test_that("get_table_comments works", {
test_that("get_table_comment works", {
if(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres")){
Sys.setenv(port="5432")
Sys.setenv(server="localhost")
Sys.setenv(user_test="runner")
Sys.setenv(pwd_test=Sys.getenv("BDD_RUNNER_PWD"))
expect_snapshot(get_table_comments(table = "test_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
expect_error(get_table_comment(table = "test_iris", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument schema n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"L\'argument table n\'est pas renseign\u00e9. ")
expect_error(get_table_comment(table = "titi_test", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")),
"Il n\'y a pas de table titi_test dans le schema public. ")
expect_snapshot(get_table_comment(table = "retest_iris", schema = "public", db = "test_datalibaba", user = "test", server = Sys.getenv("server")))
}else{
print(DBI::dbCanConnect(RPostgres::Postgres(), host="localhost", user="runner", password=Sys.getenv("BDD_RUNNER_PWD"), dbname="postgres"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment