initial cut of deprecated bundle
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionStorage / Deprecated / VersionResultSet.pm
diff --git a/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm b/lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm
new file mode 100644 (file)
index 0000000..cc4699b
--- /dev/null
@@ -0,0 +1,49 @@
+package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResultSet;
+
+use strict;
+use warnings;
+
+use parent 'DBIx::Class::ResultSet';
+
+use Try::Tiny;
+use Time::HiRes 'gettimeofday';
+
+sub version_storage_is_installed {
+  my $self = shift;
+  try { $self->next; 1 } catch { undef }
+}
+
+sub database_version {
+  my $self = shift;
+  $self->search(undef, {
+    order_by => { -desc => 'installed' },
+    rows => 1
+  })->get_column('version')->next;
+}
+
+# this is why it's deprecated guys... Serially.
+sub create {
+  my $self = shift;
+
+  my @tm = gettimeofday();
+  my @dt = gmtime ($tm[0]);
+
+  $self->next::method({
+    version => $version,
+    installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f",
+      $dt[5] + 1900,
+      $dt[4] + 1,
+      $dt[3],
+      $dt[2],
+      $dt[1],
+      $dt[0],
+      $tm[1] / 1000, # convert to millisecs, format as up/down rounded int above
+    ),
+  });
+}
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab