1

I'm working with the Play Framework 2.2.1, for Java. I would like to have my fixtures, for my unit tests, have all the tables start their id counting at over 200.

The reason being this: Compare non-primitive Long values 127 and 128

Googling it gives a bunch of "best practice" articles, non of which include this option.

So I'm wondering if it's possible.

EDIT: To clarify, this would be for the unit tests only, not for the working environment. The unit tests are loaded via fixtures. Every test can have a different fixture, meaning the db gets wiped for ever test, meaning it would have to be done for every single table in the database on the loading of the fixture.

The Play Framework uses ebean as an abstraction layer. Play uses the H2 database for unit testing in memory.

EDIT: I ended up fixing it with a regular connection to H2. Ebeean does not seem to support this.

Community
  • 1
  • 1
KdgDev
  • 14,299
  • 46
  • 120
  • 156
  • You only want that behavior in your test db and not in the real db? How are you loading your data in the tests? – Salem Apr 07 '15 at 18:28
  • @Salem Fixtures. Play allows you to load a fixture for every test method. This all works via ebean. – KdgDev Apr 08 '15 at 09:33

1 Answers1

1

Yes it is (with most dbms at least). This sql statement works for MySQL: ALTER TABLE <table_name> AUTO_INCREMENT = 200;

This one works for H2: ALTER TABLE <table_name> ALTER COLUMN <column_name> RESTART WITH 1

Peanut
  • 3,753
  • 3
  • 31
  • 45
  • Okay, that works for altering a database from the commandline. But I'm using the Play Framework and its fixtures. I need the data defined in those fixtures to have the id numbers I defined the auto_increment to start at. So the first item I insert should have id, for instance, 200. How can I make sure the tables are generated and altered like that before the first insert happens? – KdgDev Apr 11 '15 at 16:31