Skip to content

Commit 11152c8

Browse files
schmitchvytautask
authored andcommitted
migrate id's from int to long (#104)
1 parent b847966 commit 11152c8

15 files changed

+63
-30
lines changed

src/Hangfire.PostgreSql/Entities/JobParameter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Hangfire.PostgreSql.Entities
2626
[UsedImplicitly]
2727
internal class JobParameter
2828
{
29-
public int JobId { get; set; }
29+
public long JobId { get; set; }
3030
public string Name { get; set; }
3131
public string Value { get; set; }
3232
}

src/Hangfire.PostgreSql/Entities/SqlHash.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Hangfire.PostgreSql.Entities
2727
[UsedImplicitly]
2828
internal class SqlHash
2929
{
30-
public int Id { get; set; }
30+
public long Id { get; set; }
3131
public string Key { get; set; }
3232
public string Field { get; set; }
3333
public string Value { get; set; }

src/Hangfire.PostgreSql/Entities/SqlJob.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is part of Hangfire.PostgreSql.
2-
// Copyright © 2014 Frank Hommers <http://hmm.rs/Hangfire.PostgreSql>.
2+
// Copyright 2014 Frank Hommers <http://hmm.rs/Hangfire.PostgreSql>.
33
//
44
// Hangfire.PostgreSql is free software: you can redistribute it and/or modify
55
// it under the terms of the GNU Lesser General Public License as
@@ -27,7 +27,7 @@ namespace Hangfire.PostgreSql.Entities
2727
[UsedImplicitly]
2828
internal class SqlJob
2929
{
30-
public int Id { get; set; }
30+
public long Id { get; set; }
3131
public string InvocationData { get; set; }
3232
public string Arguments { get; set; }
3333
public DateTime CreatedAt { get; set; }

src/Hangfire.PostgreSql/Entities/SqlState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Hangfire.PostgreSql.Entities
2727
[UsedImplicitly]
2828
internal class SqlState
2929
{
30-
public int JobId { get; set; }
30+
public long JobId { get; set; }
3131
public string Name { get; set; }
3232
public string Reason { get; set; }
3333
public DateTime CreatedAt { get; set; }

src/Hangfire.PostgreSql/IPersistentJobQueueMonitoringApi.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace Hangfire.PostgreSql
2626
public interface IPersistentJobQueueMonitoringApi
2727
{
2828
IEnumerable<string> GetQueues();
29-
IEnumerable<int> GetEnqueuedJobIds(string queue, int from, int perPage);
30-
IEnumerable<int> GetFetchedJobIds(string queue, int from, int perPage);
29+
IEnumerable<long> GetEnqueuedJobIds(string queue, int from, int perPage);
30+
IEnumerable<long> GetFetchedJobIds(string queue, int from, int perPage);
3131
EnqueuedAndFetchedCountDto GetEnqueuedAndFetchedCount(string queue);
3232
}
3333
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
SET search_path = 'hangfire';
2+
3+
4+
5+
DO
6+
$$
7+
BEGIN
8+
IF EXISTS (SELECT 1 FROM "schema" WHERE "version"::integer >= 11) THEN
9+
RAISE EXCEPTION 'version-already-applied';
10+
END IF;
11+
END
12+
$$;
13+
14+
ALTER TABLE hangfire.counter ALTER COLUMN id TYPE BIGINT;
15+
ALTER SEQUENCE hangfire.counter_id_seq AS BIGINT;
16+
ALTER TABLE hangfire.hash ALTER COLUMN id TYPE BIGINT;
17+
ALTER SEQUENCE hangfire.hash_id_seq AS BIGINT;
18+
ALTER TABLE hangfire.job ALTER COLUMN id TYPE BIGINT;
19+
ALTER SEQUENCE hangfire.job_id_seq AS BIGINT;
20+
ALTER TABLE hangfire.job ALTER COLUMN stateid TYPE BIGINT;
21+
ALTER TABLE hangfire.state ALTER COLUMN id TYPE BIGINT;
22+
ALTER SEQUENCE hangfire.state_id_seq AS BIGINT;
23+
ALTER TABLE hangfire.state ALTER COLUMN jobid TYPE BIGINT;
24+
ALTER TABLE hangfire.jobparameter ALTER COLUMN id TYPE BIGINT;
25+
ALTER SEQUENCE hangfire.jobparameter_id_seq AS BIGINT;
26+
ALTER TABLE hangfire.jobparameter ALTER COLUMN jobid TYPE BIGINT;
27+
ALTER TABLE hangfire.jobqueue ALTER COLUMN id TYPE BIGINT;
28+
ALTER SEQUENCE hangfire.jobqueue_id_seq AS BIGINT;
29+
ALTER TABLE hangfire.jobqueue ALTER COLUMN jobid TYPE BIGINT;
30+
ALTER TABLE hangfire.list ALTER COLUMN id TYPE BIGINT;
31+
ALTER SEQUENCE hangfire.list_id_seq AS BIGINT;
32+
ALTER TABLE hangfire.set ALTER COLUMN id TYPE BIGINT;
33+
ALTER SEQUENCE hangfire.set_id_seq AS BIGINT;

src/Hangfire.PostgreSql/PostgreSqlConnection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public override string CreateExpiredJob(
128128

129129
var invocationData = InvocationData.Serialize(job);
130130

131-
var jobId = _connection.Query<int>(
131+
var jobId = _connection.Query<long>(
132132
createJobSql,
133133
new
134134
{

src/Hangfire.PostgreSql/PostgreSqlFetchedJob.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PostgreSqlFetchedJob : IFetchedJob
4242
public PostgreSqlFetchedJob(
4343
IDbConnection connection,
4444
PostgreSqlStorageOptions options,
45-
int id,
45+
long id,
4646
string jobId,
4747
string queue)
4848
{
@@ -59,7 +59,7 @@ public PostgreSqlFetchedJob(
5959
Queue = queue;
6060
}
6161

62-
public int Id { get; private set; }
62+
public long Id { get; private set; }
6363
public string JobId { get; private set; }
6464
public string Queue { get; private set; }
6565

src/Hangfire.PostgreSql/PostgreSqlJobQueue.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public void Enqueue(string queue, string jobId)
239239
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
240240
private class FetchedJob
241241
{
242-
public int Id { get; set; }
243-
public int JobId { get; set; }
242+
public long Id { get; set; }
243+
public long JobId { get; set; }
244244
public string Queue { get; set; }
245245
public DateTime? FetchedAt { get; set; }
246246
public int UpdateCount { get; set; }

src/Hangfire.PostgreSql/PostgreSqlJobQueueMonitoringApi.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ SELECT DISTINCT ""queue""
5050
return _connection.Query(sqlQuery).Select(x => (string)x.queue).ToList();
5151
}
5252

53-
public IEnumerable<int> GetEnqueuedJobIds(string queue, int @from, int perPage)
53+
public IEnumerable<long> GetEnqueuedJobIds(string queue, int @from, int perPage)
5454
{
5555
return GetQueuedOrFetchedJobIds(queue, false, @from, perPage);
5656
}
5757

58-
private IEnumerable<int> GetQueuedOrFetchedJobIds(string queue, bool fetched, int @from, int perPage)
58+
private IEnumerable<long> GetQueuedOrFetchedJobIds(string queue, bool fetched, int @from, int perPage)
5959
{
6060
string sqlQuery = string.Format(@"
6161
SELECT j.""id""
@@ -67,13 +67,13 @@ AND j.""id"" IS NOT NULL
6767
LIMIT @count OFFSET @start;
6868
", fetched ? "IS NOT NULL" : "IS NULL");
6969

70-
return _connection.Query<int>(
70+
return _connection.Query<long>(
7171
sqlQuery,
7272
new {queue = queue, start = @from, count = perPage})
7373
.ToList();
7474
}
7575

76-
public IEnumerable<int> GetFetchedJobIds(string queue, int @from, int perPage)
76+
public IEnumerable<long> GetFetchedJobIds(string queue, int @from, int perPage)
7777
{
7878
return GetQueuedOrFetchedJobIds(queue, true, @from, perPage);
7979
}

src/Hangfire.PostgreSql/PostgreSqlMonitoringApi.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ private T UseConnection<T>(Func<NpgsqlConnection, T> action)
473473
}
474474
}
475475

476-
private JobList<EnqueuedJobDto> EnqueuedJobs(NpgsqlConnection connection, IEnumerable<int> jobIds)
476+
private JobList<EnqueuedJobDto> EnqueuedJobs(NpgsqlConnection connection, IEnumerable<long> jobIds)
477477
{
478478
string enqueuedJobsSql = @"
479479
SELECT j.""id"" ""Id"", j.""invocationdata"" ""InvocationData"", j.""arguments"" ""Arguments"", j.""createdat"" ""CreatedAt"", j.""expireat"" ""ExpireAt"", s.""name"" ""StateName"", s.""reason"" ""StateReason"", s.""data"" ""StateData""
@@ -581,7 +581,7 @@ private static JobList<TDto> DeserializeJobs<TDto>(
581581

582582
private JobList<FetchedJobDto> FetchedJobs(
583583
NpgsqlConnection connection,
584-
IEnumerable<int> jobIds)
584+
IEnumerable<long> jobIds)
585585
{
586586
string fetchedJobsSql = @"
587587
SELECT j.""id"" ""Id"", j.""invocationdata"" ""InvocationData"", j.""arguments"" ""Arguments"", j.""createdat"" ""CreatedAt"",

tests/Hangfire.PostgreSql.Tests/ExpirationManagerFacts.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void Execute_Processes_HashTable()
201201
}
202202
}
203203

204-
private static int CreateExpirationEntry(NpgsqlConnection connection, DateTime? expireAt)
204+
private static long CreateExpirationEntry(NpgsqlConnection connection, DateTime? expireAt)
205205
{
206206
string insertSqlNull = @"
207207
insert into """ + GetSchemaName() + @""".""counter""(""key"", ""value"", ""expireat"")
@@ -217,11 +217,11 @@ private static int CreateExpirationEntry(NpgsqlConnection connection, DateTime?
217217
((long)(DateTime.UtcNow - expireAt.Value).TotalSeconds).ToString(CultureInfo.InvariantCulture));
218218

219219
var id = connection.Query(insertSql).Single();
220-
var recordId = (int)id.id;
220+
var recordId = (long)id.id;
221221
return recordId;
222222
}
223223

224-
private static bool IsEntryExpired(NpgsqlConnection connection, int entryId)
224+
private static bool IsEntryExpired(NpgsqlConnection connection, long entryId)
225225
{
226226
var count = connection.Query<long>(
227227
@"select count(*) from """ + GetSchemaName() + @""".""counter"" where ""id"" = @id", new { id = entryId }).Single();

tests/Hangfire.PostgreSql.Tests/PostgreSqlConnectionFacts.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void CreateExpiredJob_CreatesAJobInTheStorage_AndSetsItsParameters()
191191
var sqlJob = sql.Query(@"select * from """ + GetSchemaName() + @""".""job""").Single();
192192
Assert.Equal(jobId, sqlJob.id.ToString());
193193
Assert.Equal(createdAt, sqlJob.createdat);
194-
Assert.Null((int?) sqlJob.stateid);
194+
Assert.Null((long?) sqlJob.stateid);
195195
Assert.Null((string) sqlJob.statename);
196196

197197
var invocationData = JobHelper.FromJson<InvocationData>((string) sqlJob.invocationdata);
@@ -243,7 +243,7 @@ public void GetJobData_ReturnsResult_WhenJobExists()
243243
{
244244
var job = Job.FromExpression(() => SampleMethod("wrong"));
245245

246-
var jobId = (int) sql.Query(
246+
var jobId = (long) sql.Query(
247247
arrangeSql,
248248
new
249249
{
@@ -312,9 +312,9 @@ public void GetStateData_ReturnsCorrectData()
312312
{"Key", "Value"}
313313
};
314314

315-
var jobId = (int) sql.Query(createJobSql).Single().id;
315+
var jobId = (long) sql.Query(createJobSql).Single().id;
316316

317-
var stateId = (int) sql.Query(
317+
var stateId = (long) sql.Query(
318318
createStateSql,
319319
new {jobId = jobId, name = "Name", reason = "Reason", @data = JobHelper.ToJson(data)}).Single().id;
320320

@@ -347,7 +347,7 @@ public void GetJobData_ReturnsJobLoadException_IfThereWasADeserializationExcepti
347347
arguments = "['Arguments']"
348348
}).Single();
349349

350-
var result = connection.GetJobData(((int) jobId.id).ToString());
350+
var result = connection.GetJobData(((long) jobId.id).ToString());
351351

352352
Assert.NotNull(result.LoadException);
353353
});
@@ -493,7 +493,7 @@ public void GetParameter_ReturnsParameterValue_WhenJobExists()
493493
";
494494
UseConnections((sql, connection) =>
495495
{
496-
var id = sql.Query<int>(
496+
var id = sql.Query<long>(
497497
arrangeSql,
498498
new {name = "name", value = "value"}).Single();
499499

tests/Hangfire.PostgreSql.Tests/PostgreSqlFetchedJobFacts.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ public void Dispose_SetsFetchedAtValueToNull_IfThereWereNoCallsToComplete()
146146
});
147147
}
148148

149-
private static int CreateJobQueueRecord(IDbConnection connection, string jobId, string queue)
149+
private static long CreateJobQueueRecord(IDbConnection connection, string jobId, string queue)
150150
{
151151
string arrangeSql = @"
152152
insert into """ + GetSchemaName() + @""".""jobqueue"" (""jobid"", ""queue"", ""fetchedat"")
153153
values (@id, @queue, now() at time zone 'utc') returning ""id""";
154154

155155
return
156-
(int)
156+
(long)
157157
connection.Query(arrangeSql, new {id = Convert.ToInt32(jobId, CultureInfo.InvariantCulture), queue = queue})
158158
.Single()
159159
.id;

tests/Hangfire.PostgreSql.Tests/PostgreSqlJobQueueFacts.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void Dequeue_ShouldFetchAJob_FromTheSpecifiedQueue(bool useNativeDatabas
162162
// Arrange
163163
UseConnection(connection =>
164164
{
165-
var id = (int) connection.Query(
165+
var id = (long) connection.Query(
166166
arrangeSql,
167167
new {jobId = 1, queue = "default"}).Single().id;
168168
var queue = CreateJobQueue(connection, useNativeDatabaseTransactions);

0 commit comments

Comments
 (0)