source: trunk/LATMOS-Accounts/scripts/build_orig_schema @ 2380

Last change on this file since 2380 was 2171, checked in by nanardon, 5 years ago

Maj schema SQL de base

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use File::Slurp;
9use DateTime;
10
11=head1 NAME
12
13    la-build_orig_schema - Tools to generate initial SQL schema
14
15=head1 SYNOPSIS
16
17    la-build_orig_schema
18
19=head1 DESCRIPTION
20
21
22=cut
23
24GetOptions(
25    'c|config=s'        => \my $config,
26    'b|base=s'          => \my $base,
27    'help'              => sub { pod2usage(0) },
28) or pod2usage();
29
30=head1 OPTIONS
31
32=over 4
33
34=item -c|--config configdir
35
36Use this configuration directory instead of the default one.
37
38=item -b|--base basename
39
40Query this specific base instead of the default one.
41
42=back
43
44=cut
45
46my $LA = LATMOS::Accounts->new($config, noacl => 1);
47my $labase = $LA->base($base);
48$labase && $labase->load or die l("Cannot load base %s\n", $base);
49
50my $LAVersion = LATMOS::Accounts->VERSION;
51my $version = $labase->get_global_value('schema_version');
52my $date = DateTime->now->iso8601;
53
54my $text = <<EOF;
55--- DataBase Schema for LATMOS-Accounts $LAVersion
56--- Schema version $version build on $date
57
58--- To properly deploy as Postgresql Admin run:
59--- CREATE ROLE  laccounts LOGIN PASSWORD 'laccounts' ;
60--- CREATE DATABASE laccounts OWNER laccounts encoding 'UTF-8' ;
61
62EOF
63
64my $command = sprintf(
65    "pg_dump -x -O -s -h %s -p %d -U %s %s",
66    $labase->{_db}->{pg_host},
67    $labase->{_db}->{pg_port},
68    $labase->{_db}->{pg_user},
69    $labase->{_db}->{pg_db},
70);
71
72warn $command;
73
74open(my $handle, "$command |") or die "Cannot run pg_dump";
75while (<$handle>) {
76    $text .= $_;
77}
78close($handle);
79
80$text .= "\n";
81
82$text .= "INSERT INTO settings (varname, val) VALUES ('schema_version', '$version');\n";
83
84print $text;
Note: See TracBrowser for help on using the repository browser.