Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision beafcfad

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID beafcfad4e5a9d4f69a498a04ad3c10ff92fe7bf
  • Vorgänger 85724239
  • Nachfolger 8dadca2c

DB-Upgrade cvar-configs: sortkey neu bauen, um mit NULLs klarzukommen

Unterschiede anzeigen:

sql/Pg-upgrade2/custom_variable_configs_column_type_text.pl
1
# @tag: custom_variable_configs_column_type_text
2
# @description: Spaltentypen in 'custom_varialbe_configs' anpassen & schärfere Restriktionen
3
# @depends: release_3_0_0
4
package SL::DBUpgrade2::custom_variable_configs_column_type_text;
5

  
6
use utf8;
7
use strict;
8

  
9
use parent qw(SL::DBUpgrade2::Base);
10

  
11
sub run {
12
  my ($self) = @_;
13

  
14
  # Fix 'sortkey' column to not contain NULLs
15
  my $q_update = qq|UPDATE custom_variable_configs SET sortkey = ? WHERE id = ?|;
16
  my $h_update = $self->dbh->prepare($q_update) || die $self->dbh->errstr;
17

  
18
  my $q_select = <<SQL;
19
    SELECT id, module
20
    FROM custom_variable_configs
21
    ORDER BY module ASC, sortkey ASC NULLS LAST, id ASC
22
SQL
23

  
24
  my $previous_module = '';
25
  my $sortkey         = 0;
26
  foreach my $entry (@{ $self->dbh->selectall_arrayref($q_select) }) {
27
    $sortkey         = $previous_module eq $entry->[1] ? $sortkey + 1 : 1;
28
    $previous_module = $entry->[1];
29

  
30
    $h_update->execute($sortkey, $entry->[0]) || die $self->dbh->errstr;
31
  }
32

  
33
  $h_update->finish;
34

  
35
  # Apply structure upgrade
36
  my @statements = (
37
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN type   TYPE TEXT|,
38
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN module TYPE TEXT|,
39

  
40
    qq|UPDATE custom_variable_configs SET searchable          = FALSE WHERE searchable          IS NULL|,
41
    qq|UPDATE custom_variable_configs SET includeable         = FALSE WHERE includeable         IS NULL|,
42
    qq|UPDATE custom_variable_configs SET included_by_default = FALSE WHERE included_by_default IS NULL|,
43

  
44
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN searchable          SET NOT NULL|,
45
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN includeable         SET NOT NULL|,
46
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN included_by_default SET NOT NULL|,
47
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN name                SET NOT NULL|,
48
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN description         SET NOT NULL|,
49
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN type                SET NOT NULL|,
50
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN module              SET NOT NULL|,
51
    qq|ALTER TABLE custom_variable_configs ALTER COLUMN sortkey             SET NOT NULL|,
52

  
53
    qq|ALTER TABLE custom_variable_configs
54
       ADD CONSTRAINT custom_variable_configs_name_description_type_module_not_empty
55
       CHECK (    type        <> ''
56
              AND module      <> ''
57
              AND name        <> ''
58
              AND description <> '')|,
59

  
60
    qq|ALTER TABLE custom_variable_configs
61
       ADD CONSTRAINT custom_variable_configs_options_not_empty_for_select
62
       CHECK ((type <> 'select') OR (COALESCE(options, '') <> ''))|,
63
  );
64

  
65
  $self->db_query($_) for @statements;
66

  
67
  return 1;
68
}
69

  
70
1;
sql/Pg-upgrade2/custom_variable_configs_column_type_text.sql
1
-- @tag: custom_variable_configs_column_type_text
2
-- @description: Spaltentypen in 'custom_varialbe_configs' anpassen & schärfere Restriktionen
3
-- @depends: release_3_0_0
4
-- @charset: utf-8
5
ALTER TABLE custom_variable_configs ALTER COLUMN type   TYPE TEXT;
6
ALTER TABLE custom_variable_configs ALTER COLUMN module TYPE TEXT;
7

  
8
UPDATE custom_variable_configs SET searchable          = FALSE WHERE searchable          IS NULL;
9
UPDATE custom_variable_configs SET includeable         = FALSE WHERE includeable         IS NULL;
10
UPDATE custom_variable_configs SET included_by_default = FALSE WHERE included_by_default IS NULL;
11

  
12
ALTER TABLE custom_variable_configs ALTER COLUMN searchable          SET NOT NULL;
13
ALTER TABLE custom_variable_configs ALTER COLUMN includeable         SET NOT NULL;
14
ALTER TABLE custom_variable_configs ALTER COLUMN included_by_default SET NOT NULL;
15
ALTER TABLE custom_variable_configs ALTER COLUMN name                SET NOT NULL;
16
ALTER TABLE custom_variable_configs ALTER COLUMN description         SET NOT NULL;
17
ALTER TABLE custom_variable_configs ALTER COLUMN type                SET NOT NULL;
18
ALTER TABLE custom_variable_configs ALTER COLUMN module              SET NOT NULL;
19
ALTER TABLE custom_variable_configs ALTER COLUMN sortkey             SET NOT NULL;
20

  
21
ALTER TABLE custom_variable_configs
22
ADD CONSTRAINT custom_variable_configs_name_description_type_module_not_empty
23
CHECK (    type        <> ''
24
       AND module      <> ''
25
       AND name        <> ''
26
       AND description <> '');
27

  
28
ALTER TABLE custom_variable_configs
29
ADD CONSTRAINT custom_variable_configs_options_not_empty_for_select
30
CHECK ((type <> 'select') OR (COALESCE(options, '') <> ''));

Auch abrufbar als: Unified diff