Commit 4d09c3e736316e7e9b2467fffc2236b11ec6ae78
1 parent
55ecae2d
Exists in
2.9
and in
1 other branch
Atualiza view do endereço com cidade e estado opcionais
Showing
2 changed files
with
42 additions
and
0 deletions
Show diff stats
database/migrations/2023_10_24_162358_update_view_addresses.php
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +use App\Support\Database\AsView; | ||
4 | +use Illuminate\Database\Migrations\Migration; | ||
5 | + | ||
6 | +return new class extends Migration { | ||
7 | + use AsView; | ||
8 | + | ||
9 | + public function up(): void | ||
10 | + { | ||
11 | + $this->createView('addresses', '2023-10-24'); | ||
12 | + } | ||
13 | + | ||
14 | + public function down(): void | ||
15 | + { | ||
16 | + $this->createView('addresses'); | ||
17 | + } | ||
18 | +}; |
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +CREATE OR REPLACE VIEW public.addresses | ||
2 | +AS | ||
3 | +SELECT p.id, | ||
4 | + p.city_id, | ||
5 | + c.state_id, | ||
6 | + s.country_id, | ||
7 | + p.address, | ||
8 | + p.number, | ||
9 | + p.complement, | ||
10 | + p.neighborhood, | ||
11 | + p.postal_code, | ||
12 | + p.latitude, | ||
13 | + p.longitude, | ||
14 | + c.name AS city, | ||
15 | + s.abbreviation AS state_abbreviation, | ||
16 | + s.name AS state, | ||
17 | + cn.name AS country, | ||
18 | + c.ibge_code AS city_ibge_code, | ||
19 | + s.ibge_code AS state_ibge_code, | ||
20 | + cn.ibge_code AS country_ibge_code | ||
21 | +FROM places p | ||
22 | + LEFT JOIN cities c ON c.id = p.city_id | ||
23 | + LEFT JOIN states s ON s.id = c.state_id | ||
24 | + LEFT JOIN countries cn ON cn.id = s.country_id; |