]> git.openstreetmap.org Git - rails.git/commitdiff
Remove default values from id columns
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 23 Feb 2022 15:22:37 +0000 (15:22 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 23 Feb 2022 15:22:37 +0000 (15:22 +0000)
In both the case of primary keys, and also foreign key references,
there's no need to set a default value.

This doesn't have a big impact in routine situations, but can be
very confusing when debugging corner cases.

db/migrate/20220223140543_remove_id_defaults.rb [new file with mode: 0644]
db/structure.sql

diff --git a/db/migrate/20220223140543_remove_id_defaults.rb b/db/migrate/20220223140543_remove_id_defaults.rb
new file mode 100644 (file)
index 0000000..5ce01f9
--- /dev/null
@@ -0,0 +1,13 @@
+class RemoveIdDefaults < ActiveRecord::Migration[7.0]
+  def change
+    # Remove defaults from foreign key references
+    change_column_default :gpx_file_tags, :gpx_id, :from => 0, :to => nil
+    change_column_default :relation_members, :relation_id, :from => 0, :to => nil
+    change_column_default :relation_tags, :relation_id, :from => 0, :to => nil
+    change_column_default :way_tags, :way_id, :from => 0, :to => nil
+
+    # Remove defaults from primary keys
+    change_column_default :relations, :relation_id, :from => 0, :to => nil
+    change_column_default :ways, :way_id, :from => 0, :to => nil
+  end
+end
index 63aa17353a7071df5c0ed8efc1e10e8d15879bb7..dd0165ee08aabbe1ce35fc460a78cc14725f2a01 100644 (file)
@@ -753,7 +753,7 @@ CREATE TABLE public.gps_points (
 --
 
 CREATE TABLE public.gpx_file_tags (
-    gpx_id bigint DEFAULT 0 NOT NULL,
+    gpx_id bigint NOT NULL,
     tag character varying NOT NULL,
     id bigint NOT NULL
 );
@@ -1274,7 +1274,7 @@ ALTER SEQUENCE public.redactions_id_seq OWNED BY public.redactions.id;
 --
 
 CREATE TABLE public.relation_members (
-    relation_id bigint DEFAULT 0 NOT NULL,
+    relation_id bigint NOT NULL,
     member_type public.nwr_enum NOT NULL,
     member_id bigint NOT NULL,
     member_role character varying NOT NULL,
@@ -1288,7 +1288,7 @@ CREATE TABLE public.relation_members (
 --
 
 CREATE TABLE public.relation_tags (
-    relation_id bigint DEFAULT 0 NOT NULL,
+    relation_id bigint NOT NULL,
     k character varying DEFAULT ''::character varying NOT NULL,
     v character varying DEFAULT ''::character varying NOT NULL,
     version bigint NOT NULL
@@ -1300,7 +1300,7 @@ CREATE TABLE public.relation_tags (
 --
 
 CREATE TABLE public.relations (
-    relation_id bigint DEFAULT 0 NOT NULL,
+    relation_id bigint NOT NULL,
     changeset_id bigint NOT NULL,
     "timestamp" timestamp without time zone NOT NULL,
     version bigint NOT NULL,
@@ -1541,7 +1541,7 @@ CREATE TABLE public.way_nodes (
 --
 
 CREATE TABLE public.way_tags (
-    way_id bigint DEFAULT 0 NOT NULL,
+    way_id bigint NOT NULL,
     k character varying NOT NULL,
     v character varying NOT NULL,
     version bigint NOT NULL
@@ -1553,7 +1553,7 @@ CREATE TABLE public.way_tags (
 --
 
 CREATE TABLE public.ways (
-    way_id bigint DEFAULT 0 NOT NULL,
+    way_id bigint NOT NULL,
     changeset_id bigint NOT NULL,
     "timestamp" timestamp without time zone NOT NULL,
     version bigint NOT NULL,
@@ -3427,6 +3427,7 @@ INSERT INTO "schema_migrations" (version) VALUES
 ('20210511104518'),
 ('20211216185316'),
 ('20220201183346'),
+('20220223140543'),
 ('21'),
 ('22'),
 ('23'),