Migrating to postgis.

This commit is contained in:
Sergiotarxz 2024-01-14 05:45:56 +01:00
parent 5f70116da2
commit 16888b9fdb
3 changed files with 37 additions and 11 deletions

View File

@ -112,11 +112,11 @@ sub create ($self) {
description => $description,
name => $name,
type => $type,
coordinate_1 => $coordinate_1,
coordinate_2 => $coordinate_2
geometry => \['ST_MakePoint(?, ?)', $coordinate_1, $coordinate_2],
}
);
$node->insert;
$node = $node->get_from_storage;
};
if ($@) {
warn $@;

View File

@ -82,6 +82,12 @@ sub MIGRATIONS {
'ALTER TABLE conquer_teams ADD COLUMN color TEXT NOT NULL DEFAULT \'#000\';',
'ALTER TABLE conquer_teams ALTER COLUMN color SET DEFAULT \'#555\';',
'ALTER TABLE conquer_teams ALTER COLUMN color SET DEFAULT \'#aaa\';',
'CREATE EXTENSION IF NOT EXISTS postgis;',
'ALTER TABLE conquer_node ADD COLUMN geometry GEOMETRY NULL;',
'UPDATE conquer_node SET geometry=ST_MakePoint(coordinate_1, coordinate_2);',
'ALTER TABLE conquer_node ALTER COLUMN geometry SET NOT NULL;',
'ALTER TABLE conquer_node DROP COLUMN coordinate_1;',
'ALTER TABLE conquer_node DROP COLUMN coordinate_2;',
);
}

View File

@ -25,14 +25,6 @@ __PACKAGE__->add_columns(
is_nullable => 0,
default_value => \'0',
},
coordinate_1 => {
data_type => 'real',
is_nullable => 0,
},
coordinate_2 => {
data_type => 'real',
is_nullable => 0,
},
type => {
data_type => 'text',
is_nullable => 0,
@ -40,9 +32,37 @@ __PACKAGE__->add_columns(
description => {
data_type => 'text',
is_nullable => 0,
}
},
geometry => {
data_type => 'geometry',
is_nullable => 0,
},
);
sub coordinate_2($self) {
require BurguillosInfo::Schema;
my $resultset = BurguillosInfo::Schema->Schema->resultset('ConquerNode');
my ($new_self) = $resultset->search({uuid => $self->uuid}, {
'+select' => {
ST_Y => { ST_Centroid => 'geometry' },
-as => 'coordinate_2',
}
});
return $new_self->get_column('coordinate_2');
}
sub coordinate_1($self) {
require BurguillosInfo::Schema;
my $resultset = BurguillosInfo::Schema->Schema->resultset('ConquerNode');
my ($new_self) = $resultset->search({uuid => $self->uuid}, {
'+select' => {
ST_X => { ST_Centroid => 'geometry' },
-as => 'coordinate_1',
}
});
return $new_self->get_column('coordinate_1');
}
sub serialize ( $self, $player = undef ) {
$self = $self->get_from_storage();
my $return = {