Skip to content

Commit b13bdc9

Browse files
committed
#3459 Postgres varchar default to no length (aka text)
Change Postgres platform to default a String to varchar [with no length defined] rather than varchar(255)
1 parent 0a5c3ce commit b13bdc9

File tree

19 files changed

+175
-168
lines changed

19 files changed

+175
-168
lines changed

ebean-api/src/main/java/io/ebean/config/dbplatform/DbPlatformType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public String renderType(int deployLength, int deployScale) {
172172
* </p>
173173
*/
174174
public String renderType(int deployLength, int deployScale, boolean strict) {
175-
176175
int len = deployLength != 0 ? deployLength : defaultLength;
177176
if (len > maxLength) {
178177
return fallback.renderType(deployLength, deployScale, strict);
@@ -182,7 +181,6 @@ public String renderType(int deployLength, int deployScale, boolean strict) {
182181
if ((canHaveLength || !strict) && len > 0) {
183182
renderLengthScale(len, deployScale, sb);
184183
}
185-
186184
return sb.toString();
187185
}
188186
}

ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.0__initial.sql

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
-- apply changes
33
create table migtest_ckey_assoc (
44
id integer generated by default as identity not null,
5-
assoc_one varchar(255),
5+
assoc_one varchar,
66
constraint pk_migtest_ckey_assoc primary key (id)
77
);
88

99
create table migtest_ckey_detail (
1010
id integer generated by default as identity not null,
11-
something varchar(255),
11+
something varchar,
1212
constraint pk_migtest_ckey_detail primary key (id)
1313
);
1414

1515
create table migtest_ckey_parent (
1616
one_key integer not null,
1717
two_key varchar(127) not null,
18-
name varchar(255),
18+
name varchar,
1919
version integer not null,
2020
constraint pk_migtest_ckey_parent primary key (one_key,two_key)
2121
);
@@ -62,7 +62,7 @@ create table migtest_e_basic (
6262
description varchar(127),
6363
description_file bytea,
6464
json_list json,
65-
a_lob varchar(255) default 'X' not null,
65+
a_lob varchar default 'X' not null,
6666
some_date timestamptz,
6767
old_boolean boolean default false not null,
6868
old_boolean2 boolean,
@@ -90,21 +90,21 @@ create table migtest_e_enum (
9090

9191
create table migtest_e_history (
9292
id integer generated by default as identity not null,
93-
test_string varchar(255),
93+
test_string varchar,
9494
constraint pk_migtest_e_history primary key (id)
9595
);
9696

9797
create table migtest_e_history2 (
9898
id integer generated by default as identity not null,
99-
test_string varchar(255),
100-
obsolete_string1 varchar(255),
101-
obsolete_string2 varchar(255),
99+
test_string varchar,
100+
obsolete_string1 varchar,
101+
obsolete_string2 varchar,
102102
constraint pk_migtest_e_history2 primary key (id)
103103
);
104104

105105
create table migtest_e_history3 (
106106
id integer generated by default as identity not null,
107-
test_string varchar(255),
107+
test_string varchar,
108108
constraint pk_migtest_e_history3 primary key (id)
109109
);
110110

@@ -128,7 +128,7 @@ create table migtest_e_history6 (
128128
);
129129

130130
create table "migtest_QuOtEd" (
131-
id varchar(255) not null,
131+
id varchar not null,
132132
status1 varchar(1),
133133
status2 varchar(1),
134134
constraint ck_migtest_quoted_status1 check ( status1 in ('N','A','I')),
@@ -146,43 +146,43 @@ create table migtest_e_ref (
146146

147147
create table migtest_e_softdelete (
148148
id integer generated by default as identity not null,
149-
test_string varchar(255),
149+
test_string varchar,
150150
constraint pk_migtest_e_softdelete primary key (id)
151151
);
152152

153153
create table "table" (
154-
"index" varchar(255) not null,
155-
"from" varchar(255),
156-
"to" varchar(255),
157-
"varchar" varchar(255),
158-
"foreign" varchar(255),
159-
textfield varchar(255) not null,
154+
"index" varchar not null,
155+
"from" varchar,
156+
"to" varchar,
157+
"varchar" varchar,
158+
"foreign" varchar,
159+
textfield varchar not null,
160160
constraint uq_table_to unique ("to"),
161161
constraint uq_table_varchar unique ("varchar"),
162162
constraint pk_table primary key ("index")
163163
);
164164

165165
create table migtest_mtm_c (
166166
id integer generated by default as identity not null,
167-
name varchar(255),
167+
name varchar,
168168
constraint pk_migtest_mtm_c primary key (id)
169169
);
170170

171171
create table migtest_mtm_m (
172172
id bigint generated by default as identity not null,
173-
name varchar(255),
173+
name varchar,
174174
constraint pk_migtest_mtm_m primary key (id)
175175
);
176176

177177
create table migtest_oto_child (
178178
id integer generated by default as identity not null,
179-
name varchar(255),
179+
name varchar,
180180
constraint pk_migtest_oto_child primary key (id)
181181
);
182182

183183
create table migtest_oto_master (
184184
id bigint generated by default as identity not null,
185-
name varchar(255),
185+
name varchar,
186186
constraint pk_migtest_oto_master primary key (id)
187187
);
188188

ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.1.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ create table migtest_mtm_m_migtest_mtm_c (
155155

156156
create table migtest_mtm_m_phone_numbers (
157157
migtest_mtm_m_id bigint not null,
158-
value varchar(255) not null
158+
value varchar not null
159159
);
160160

161161

@@ -172,8 +172,8 @@ update migtest_e_history2 set test_string = 'unknown' where test_string is null;
172172
update migtest_e_history6 set test_number1 = 42 where test_number1 is null;
173173
-- apply alter tables
174174
alter table "table" alter column textfield drop not null;
175-
alter table "table" add column "select" varchar(255);
176-
alter table "table" add column textfield2 varchar(255);
175+
alter table "table" add column "select" varchar;
176+
alter table "table" add column textfield2 varchar;
177177
alter table migtest_ckey_detail add column one_key integer;
178178
alter table migtest_ckey_detail add column two_key varchar(127);
179179
alter table migtest_ckey_parent add column assoc_id integer;
@@ -185,16 +185,16 @@ alter table migtest_e_basic alter column status2 drop not null;
185185
alter table migtest_e_basic alter column a_lob drop default;
186186
alter table migtest_e_basic alter column a_lob drop not null;
187187
alter table migtest_e_basic alter column user_id drop not null;
188-
alter table migtest_e_basic add column new_string_field varchar(255) default 'foo''bar' not null;
188+
alter table migtest_e_basic add column new_string_field varchar default 'foo''bar' not null;
189189
alter table migtest_e_basic add column new_boolean_field boolean default true not null;
190190
alter table migtest_e_basic add column new_boolean_field2 boolean default true not null;
191191
alter table migtest_e_basic add column progress integer default 0 not null;
192192
alter table migtest_e_basic add column new_integer integer default 42 not null;
193193
alter table migtest_e_history alter column test_string type bigint;
194194
alter table migtest_e_history2 alter column test_string set default 'unknown';
195195
alter table migtest_e_history2 alter column test_string set not null;
196-
alter table migtest_e_history2 add column test_string2 varchar(255);
197-
alter table migtest_e_history2 add column test_string3 varchar(255) default 'unknown' not null;
196+
alter table migtest_e_history2 add column test_string2 varchar;
197+
alter table migtest_e_history2 add column test_string3 varchar default 'unknown' not null;
198198
alter table migtest_e_history2 add column new_column varchar(20);
199199
alter table migtest_e_history4 alter column test_number type bigint;
200200
alter table migtest_e_history5 add column test_boolean boolean default false not null;

ebean-test/src/test/resources/migrationtest/dbmigration/cockroach/1.3.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ drop index if exists ix_migtest_e_basic_indextest6;
2828
drop index if exists ix_table_textfield2;
2929
-- apply changes
3030
create table "migtest_QuOtEd" (
31-
id varchar(255) not null,
31+
id varchar not null,
3232
status1 varchar(1),
3333
status2 varchar(1),
3434
constraint ck_migtest_quoted_status1 check ( status1 in ('N','A','I')),
@@ -59,7 +59,7 @@ alter table migtest_e_basic alter column status drop not null;
5959
alter table migtest_e_basic alter column status2 type varchar(1);
6060
alter table migtest_e_basic alter column status2 set default 'N';
6161
alter table migtest_e_basic alter column status2 set not null;
62-
alter table migtest_e_basic alter column a_lob type varchar(255);
62+
alter table migtest_e_basic alter column a_lob type varchar;
6363
alter table migtest_e_basic alter column a_lob set default 'X';
6464
alter table migtest_e_basic alter column a_lob set not null;
6565
alter table migtest_e_basic alter column user_id set default 23;
@@ -70,8 +70,8 @@ alter table migtest_e_basic add column old_boolean2 boolean;
7070
alter table migtest_e_basic add column eref_id integer;
7171
alter table migtest_e_history2 alter column test_string drop default;
7272
alter table migtest_e_history2 alter column test_string drop not null;
73-
alter table migtest_e_history2 add column obsolete_string1 varchar(255);
74-
alter table migtest_e_history2 add column obsolete_string2 varchar(255);
73+
alter table migtest_e_history2 add column obsolete_string1 varchar;
74+
alter table migtest_e_history2 add column obsolete_string2 varchar;
7575
alter table migtest_e_history4 alter column test_number type integer;
7676
alter table migtest_e_history6 alter column test_number1 drop default;
7777
alter table migtest_e_history6 alter column test_number1 drop not null;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1434934404, 1.0__initial.sql
2-
-645855838, 1.1.sql
1+
479024598, 1.0__initial.sql
2+
51162323, 1.1.sql
33
856096334, 1.2__dropsFor_1.1.sql
4-
1769792822, 1.3.sql
4+
-1876375912, 1.3.sql
55
-1416035730, 1.4__dropsFor_1.3.sql
66
561281075, R__order_views.sql
77

ebean-test/src/test/resources/migrationtest/dbmigration/postgres/1.0__initial.sql

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
-- apply changes
33
create table migtest_ckey_assoc (
44
id integer generated by default as identity not null,
5-
assoc_one varchar(255),
5+
assoc_one varchar,
66
constraint pk_migtest_ckey_assoc primary key (id)
77
);
88

99
create table migtest_ckey_detail (
1010
id integer generated by default as identity not null,
11-
something varchar(255),
11+
something varchar,
1212
constraint pk_migtest_ckey_detail primary key (id)
1313
);
1414

1515
create table migtest_ckey_parent (
1616
one_key integer not null,
1717
version integer not null,
1818
two_key varchar(127) not null,
19-
name varchar(255),
19+
name varchar,
2020
constraint pk_migtest_ckey_parent primary key (one_key,two_key)
2121
);
2222

@@ -58,7 +58,7 @@ create table migtest_e_basic (
5858
id integer generated by default as identity not null,
5959
description_file bytea,
6060
json_list json,
61-
a_lob varchar(255) default 'X' not null,
61+
a_lob varchar default 'X' not null,
6262
some_date timestamptz,
6363
old_boolean boolean default false not null,
6464
old_boolean2 boolean,
@@ -90,21 +90,21 @@ create table migtest_e_enum (
9090

9191
create table migtest_e_history (
9292
id integer generated by default as identity not null,
93-
test_string varchar(255),
93+
test_string varchar,
9494
constraint pk_migtest_e_history primary key (id)
9595
);
9696

9797
create table migtest_e_history2 (
9898
id integer generated by default as identity not null,
99-
test_string varchar(255),
100-
obsolete_string1 varchar(255),
101-
obsolete_string2 varchar(255),
99+
test_string varchar,
100+
obsolete_string1 varchar,
101+
obsolete_string2 varchar,
102102
constraint pk_migtest_e_history2 primary key (id)
103103
);
104104

105105
create table migtest_e_history3 (
106106
id integer generated by default as identity not null,
107-
test_string varchar(255),
107+
test_string varchar,
108108
constraint pk_migtest_e_history3 primary key (id)
109109
);
110110

@@ -128,7 +128,7 @@ create table migtest_e_history6 (
128128
);
129129

130130
create table "migtest_QuOtEd" (
131-
id varchar(255) not null,
131+
id varchar not null,
132132
status1 varchar(1),
133133
status2 varchar(1),
134134
constraint ck_migtest_quoted_status1 check ( status1 in ('N','A','I')),
@@ -146,17 +146,17 @@ create table migtest_e_ref (
146146

147147
create table migtest_e_softdelete (
148148
id integer generated by default as identity not null,
149-
test_string varchar(255),
149+
test_string varchar,
150150
constraint pk_migtest_e_softdelete primary key (id)
151151
);
152152

153153
create table "table" (
154-
"index" varchar(255) not null,
155-
"from" varchar(255),
156-
"to" varchar(255),
157-
"varchar" varchar(255),
158-
"foreign" varchar(255),
159-
textfield varchar(255) not null,
154+
"index" varchar not null,
155+
"from" varchar,
156+
"to" varchar,
157+
"varchar" varchar,
158+
"foreign" varchar,
159+
textfield varchar not null,
160160
constraint uq_table_to unique ("to"),
161161
constraint uq_table_varchar unique ("varchar"),
162162
constraint pk_table primary key ("index")
@@ -165,25 +165,25 @@ comment on column "table"."index" is 'this is a comment';
165165

166166
create table migtest_mtm_c (
167167
id integer generated by default as identity not null,
168-
name varchar(255),
168+
name varchar,
169169
constraint pk_migtest_mtm_c primary key (id)
170170
);
171171

172172
create table migtest_mtm_m (
173173
id bigint generated by default as identity not null,
174-
name varchar(255),
174+
name varchar,
175175
constraint pk_migtest_mtm_m primary key (id)
176176
);
177177

178178
create table migtest_oto_child (
179179
id integer generated by default as identity not null,
180-
name varchar(255),
180+
name varchar,
181181
constraint pk_migtest_oto_child primary key (id)
182182
);
183183

184184
create table migtest_oto_master (
185185
id bigint generated by default as identity not null,
186-
name varchar(255),
186+
name varchar,
187187
constraint pk_migtest_oto_master primary key (id)
188188
);
189189

0 commit comments

Comments
 (0)