From bf2d93229f60fa0d1fe8465eb59175a911aa4a4d Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 11 Aug 2019 05:51:58 +0500 Subject: [PATCH] Fix PostgreSQL sequence start values --- db/migrate/20181129203927_initial_migration.rb | 14 ++++++++++++++ db/structure.sql | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/db/migrate/20181129203927_initial_migration.rb b/db/migrate/20181129203927_initial_migration.rb index b0b8c16..0148b63 100644 --- a/db/migrate/20181129203927_initial_migration.rb +++ b/db/migrate/20181129203927_initial_migration.rb @@ -5,6 +5,7 @@ class InitialMigration < ActiveRecord::Migration[6.0] change_types change_functions change_tables + change_sequences change_constraints change_triggers end @@ -357,6 +358,19 @@ private end end + def change_sequences + reversible do |dir| + dir.up do + execute <<~SQL + ALTER SEQUENCE contact_networks_id_seq START WITH 100; + ALTER SEQUENCE federal_subjects_id_seq START WITH 100; + ALTER SEQUENCE contacts_id_seq START WITH 4000; + ALTER SEQUENCE people_id_seq START WITH 3000; + SQL + end + end + end + def change_constraints constraint :contacts, :value, <<~SQL is_good_small_text(value) diff --git a/db/structure.sql b/db/structure.sql index ec7ddad..8a98161 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -423,7 +423,7 @@ CREATE TABLE public.contact_networks ( -- CREATE SEQUENCE public.contact_networks_id_seq - START WITH 1 + START WITH 100 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -457,7 +457,7 @@ CREATE TABLE public.contacts ( -- CREATE SEQUENCE public.contacts_id_seq - START WITH 1 + START WITH 4000 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -496,7 +496,7 @@ CREATE TABLE public.federal_subjects ( -- CREATE SEQUENCE public.federal_subjects_id_seq - START WITH 1 + START WITH 100 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -606,7 +606,7 @@ CREATE TABLE public.people ( -- CREATE SEQUENCE public.people_id_seq - START WITH 1 + START WITH 3000 INCREMENT BY 1 NO MINVALUE NO MAXVALUE